ZQuest Classic Coverage Report


Directory: src/
File: src/zc/zc_sys.cpp
Date: 2025-07-14 06:41:52
Exec Total Coverage
Lines: 2013 4565 44.1%
Functions: 142 337 42.1%
Branches: 1340 3758 35.7%

Line Branch Exec Source
1 #include "zc/zc_sys.h"
2
3 #include "allegro/gfx.h"
4 #include "allegro/gui.h"
5 #include "allegro/inline/draw.inl"
6 #include "allegro5/joystick.h"
7 #include "base/files.h"
8 #include "base/render.h"
9 #include "base/zdefs.h"
10 #include "zalleg/zalleg.h"
11 #include "base/qrs.h"
12 #include "base/dmap.h"
13 #include <functional>
14 #include <queue>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <cstring>
18 #include <math.h>
19 #include <map>
20 #include <filesystem>
21 #include <ctype.h>
22 #include <sstream>
23 #include "base/version.h"
24 #include "base/zc_alleg.h"
25 #include "gamedata.h"
26 #include "zc/replay_upload.h"
27 #include "zc/zc_init.h"
28 #include "init.h"
29 #include "zc/replay.h"
30 #include "zc/cheats.h"
31 #include "zc/render.h"
32 #include "base/zc_math.h"
33 #include "base/zapp.h"
34 #include "dialog/cheatkeys.h"
35 #include "metadata/metadata.h"
36 #include "zc/zelda.h"
37 #include "zc/saves.h"
38 #include "tiles.h"
39 #include "base/colors.h"
40 #include "pal.h"
41 #include "base/zsys.h"
42 #include "base/qst.h"
43 #include "zc/zc_sys.h"
44 #include "play_midi.h"
45 #include "gui/jwin_a5.h"
46 #include "base/jwinfsel.h"
47 #include "base/gui.h"
48 #include "midi.h"
49 #include "subscr.h"
50 #include "zc/maps.h"
51 #include "sprite.h"
52 #include "zc/guys.h"
53 #include "zc/hero.h"
54 #include "zc/title.h"
55 #include "particles.h"
56 #include "sound/zcmusic.h"
57 #include "zc/ffscript.h"
58 #include "dialog/info.h"
59 #include "dialog/alert.h"
60 #include "zc/combos.h"
61 #include "zc/jit.h"
62 #include "zc/zc_subscr.h"
63 #include <fmt/format.h>
64 #include "zconsole/ConsoleLogger.h"
65 #include "zinfo.h"
66 #include "base/misctypes.h"
67 #include "music_playback.h"
68 #include "base/new_menu.h"
69 #include "base/files.h"
70 #include "iter.h"
71
72 #ifdef __EMSCRIPTEN__
73 #include "base/emscripten_utils.h"
74 #endif
75
76 using namespace std::chrono_literals;
77
78 extern bool Playing;
79 int32_t sfx_voice[WAV_COUNT];
80 int32_t d_stringloader(int32_t msg,DIALOG *d,int32_t c);
81 int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c);
82
83 static ALLEGRO_JOYSTICK* gamepad_dlg_cur_joystick;
84 static int32_t d_joylist_proc(int32_t msg,DIALOG *d,int32_t c);
85
86 extern byte monochrome_console;
87
88 extern sprite_list guys, items, Ewpns, Lwpns, chainlinks, decorations;
89 extern int32_t loadlast;
90 extern char *sfx_string[WAV_COUNT];
91 byte use_dwm_flush;
92 byte use_save_indicator;
93 int32_t paused_midi_pos = 0;
94 byte midi_suspended = 0;
95 byte zc_192b163_warp_compatibility;
96 bool epilepsyFlashReduction;
97 signed char pause_in_background_menu_init = 0;
98 byte pause_in_background = 0;
99 bool is_sys_pal = false;
100 static bool load_control_called_this_frame;
101 extern PALETTE* hw_palette;
102 extern bool update_hw_pal;
103 extern const char* dmaplist(int32_t index, int32_t* list_size);
104 int32_t getnumber(const char *prompt,int32_t initialval);
105
106 extern bool kb_typing_mode; //script only, for disbaling key presses affecting Hero, etc.
107 extern int32_t cheat_modifier_keys[4]; //two options each, default either control and either shift
108
109 #ifdef ALLEGRO_LINUX
110 static const char *samplepath = "samplesoundset/patches.dat";
111 #endif
112 char qst_files_path[2048];
113
114 extern TopMenu the_player_menu;
115 #ifdef _MSC_VER
116 #define getcwd _getcwd
117 #endif
118
119 bool rF11();
120 bool rI();
121 bool rQ();
122 bool zc_key_pressed();
123
124 #ifdef _WIN32
125
126 // This should only be necessary for MinGW, since it doesn't have a dwmapi.h. Add another #ifdef if you like.
127 extern "C"
128 {
129 typedef HRESULT(WINAPI *t_DwmFlush)();
130 typedef HRESULT(WINAPI *t_DwmIsCompositionEnabled)(BOOL *pfEnabled);
131 }
132
133 void do_DwmFlush()
134 {
135 static HMODULE shell = LoadLibrary("dwmapi.dll");
136
137 if(!shell)
138 return;
139
140 static t_DwmFlush flush=reinterpret_cast<t_DwmFlush>(GetProcAddress(shell, "DwmFlush"));
141 static t_DwmIsCompositionEnabled isEnabled=reinterpret_cast<t_DwmIsCompositionEnabled>(GetProcAddress(shell, "DwmIsCompositionEnabled"));
142
143 BOOL enabled;
144 isEnabled(&enabled);
145
146 if(isEnabled)
147 flush();
148 }
149
150 #endif // _WIN32
151
152 312 void zc_exit(int code)
153 {
154 extern CConsoleLoggerEx zscript_coloured_console;
155
156 312 set_is_exiting();
157
158
1/2
✓ Branch 0 taken 312 times.
✗ Branch 1 not taken.
312 if (replay_get_mode() == ReplayMode::Record) replay_save();
159 312 replay_stop();
160 312 music_stop();
161 312 kill_sfx();
162
163
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 304 times.
312 if (get_qr(qr_OLD_SCRIPT_VOLUME))
164 {
165 //restore user volume settings
166
2/2
✓ Branch 0 taken 303 times.
✓ Branch 1 taken 1 times.
304 if (FFCore.coreflags & FFCORE_SCRIPTED_MIDI_VOLUME)
167 {
168 1 master_volume(-1, ((int32_t)FFCore.usr_midi_volume));
169 1 }
170
2/2
✓ Branch 0 taken 303 times.
✓ Branch 1 taken 1 times.
304 if (FFCore.coreflags & FFCORE_SCRIPTED_DIGI_VOLUME)
171 {
172 1 master_volume((int32_t)(FFCore.usr_digi_volume), 1);
173 1 }
174
2/2
✓ Branch 0 taken 303 times.
✓ Branch 1 taken 1 times.
304 if (FFCore.coreflags & FFCORE_SCRIPTED_MUSIC_VOLUME)
175 {
176 1 emusic_volume = (int32_t)FFCore.usr_music_volume;
177 1 }
178
1/2
✓ Branch 0 taken 304 times.
✗ Branch 1 not taken.
304 if (FFCore.coreflags & FFCORE_SCRIPTED_SFX_VOLUME)
179 {
180 sfx_volume = (int32_t)FFCore.usr_sfx_volume;
181 }
182 304 }
183
1/2
✓ Branch 0 taken 312 times.
✗ Branch 1 not taken.
312 if ( FFCore.coreflags&FFCORE_SCRIPTED_PANSTYLE )
184 {
185 pan_style = (int32_t)FFCore.usr_panstyle;
186 }
187 312 save_game_configs();
188
189 312 zscript_coloured_console.kill();
190 312 jit_shutdown();
191 312 quit_game();
192
193 312 Z_message("ZQuest Classic website: https://zquestclassic.com\n");
194 312 Z_message("ZQuest Classic docs: https://docs.zquestclassic.com\n");
195
196 312 allegro_exit();
197 312 exit(code);
198 }
199
200 93579 bool flash_reduction_enabled(bool check_qr)
201 {
202
4/4
✓ Branch 0 taken 89154 times.
✓ Branch 1 taken 4425 times.
✓ Branch 2 taken 87624 times.
✓ Branch 3 taken 92049 times.
93579 return (check_qr && get_qr(qr_EPILEPSY)) || epilepsyFlashReduction || replay_is_debug();
203 }
204
205 // Dialogue largening
206 void large_dialog(DIALOG *d)
207 {
208 large_dialog(d, 1.5);
209 }
210
211 void large_dialog(DIALOG *d, float RESIZE_AMT)
212 {
213 if(!d[0].d1)
214 {
215 d[0].d1 = 1;
216 int32_t oldwidth = d[0].w;
217 int32_t oldheight = d[0].h;
218 int32_t oldx = d[0].x;
219 int32_t oldy = d[0].y;
220 d[0].x -= int32_t(d[0].w/RESIZE_AMT);
221 d[0].y -= int32_t(d[0].h/RESIZE_AMT);
222 d[0].w = int32_t(d[0].w*RESIZE_AMT);
223 d[0].h = int32_t(d[0].h*RESIZE_AMT);
224
225 for(int32_t i=1; d[i].proc !=NULL; i++)
226 {
227 // Place elements horizontally
228 double xpc = ((double)(d[i].x - oldx) / (double)oldwidth);
229 d[i].x = int32_t(d[0].x + (xpc*d[0].w));
230
231 if(d[i].proc != d_stringloader)
232 {
233 if(d[i].proc==d_bitmap_proc)
234 {
235 d[i].w *= 2;
236 }
237 else d[i].w = int32_t(d[i].w*RESIZE_AMT);
238 }
239
240 // Place elements vertically
241 double ypc = ((double)(d[i].y - oldy) / (double)oldheight);
242 d[i].y = int32_t(d[0].y + (ypc*d[0].h));
243
244 // Vertically resize elements
245 if(d[i].proc == jwin_edit_proc || d[i].proc == jwin_check_proc || d[i].proc == jwin_checkfont_proc)
246 {
247 d[i].h = int32_t((double)d[i].h*1.5);
248 }
249 else if(d[i].proc == jwin_droplist_proc || d[i].proc == d_joylist_proc)
250 {
251 d[i].y += int32_t((double)d[i].h*0.25);
252 d[i].h = int32_t((double)d[i].h*1.25);
253 }
254 else if(d[i].proc==d_bitmap_proc)
255 {
256 d[i].h *= 2;
257 }
258 else d[i].h = int32_t(d[i].h*RESIZE_AMT);
259
260 // Fix frames
261 if(d[i].proc == jwin_frame_proc)
262 {
263 d[i].x++;
264 d[i].y++;
265 d[i].w-=4;
266 d[i].h-=4;
267 }
268 }
269 }
270
271 for(int32_t i=1; d[i].proc!=NULL; i++)
272 {
273 if(d[i].proc==jwin_slider_proc)
274 continue;
275
276 // Bigger font
277 bool bigfontproc = (d[i].proc != d_midilist_proc && d[i].proc != jwin_droplist_proc && d[i].proc != jwin_abclist_proc && d[i].proc != jwin_list_proc && d[i].proc != d_joylist_proc);
278
279 if(!d[i].dp2 && bigfontproc)
280 {
281 d[i].dp2 = get_zc_font(font_lfont_l);
282 }
283 else if(!bigfontproc)
284 {
285 ((ListData *)d[i].dp)->font = &a4fonts[font_lfont_l];
286 }
287
288 // Make checkboxes work
289 if(d[i].proc == jwin_check_proc)
290 d[i].proc = jwin_checkfont_proc;
291 else if(d[i].proc == jwin_radio_proc)
292 d[i].proc = jwin_radiofont_proc;
293 }
294
295 jwin_center_dialog(d);
296 }
297
298 static char cfg_sect[] = "zeldadx"; //We need to rename this.
299 static char ctrl_sect[] = "Controls";
300 static char sfx_sect[] = "Volume";
301
302 int32_t d_dummy_proc(int32_t,DIALOG *,int32_t)
303 {
304 return D_O_K;
305 }
306
307 bool is_reserved_key(int c)
308 {
309 switch(c)
310 {
311 case KEY_ESC:
312 return true;
313 }
314 return false;
315 }
316 bool is_reserved_keycombo(int c, int modflag)
317 {
318 if(c==KEY_F4 && (modflag&KB_ALT_FLAG))
319 return true;
320 return false;
321 }
322 bool checkcheat(Cheat cheat)
323 {
324 if(cheatkeys[cheat][0] && zc_readkey(cheatkeys[cheat][0]))
325 return true; //Main key pressed
326 if(cheatkeys[cheat][1] && zc_readkey(cheatkeys[cheat][1]))
327 return true; //Alt key pressed
328 return false;
329 }
330 312 void load_default_cheatkeys()
331 {
332 312 memset(cheatkeys, 0, sizeof(cheatkeys));
333 312 cheatkeys[Cheat::Life][0] = KEY_H;
334 312 cheatkeys[Cheat::Life][1] = KEY_ASTERISK;
335 312 cheatkeys[Cheat::Magic][0] = KEY_M;
336 312 cheatkeys[Cheat::Magic][1] = KEY_SLASH_PAD;
337 312 cheatkeys[Cheat::Rupies][0] = KEY_R;
338 312 cheatkeys[Cheat::Bombs][0] = KEY_B;
339 312 cheatkeys[Cheat::Arrows][0] = KEY_A;
340 312 cheatkeys[Cheat::Clock][0] = KEY_I;
341 312 cheatkeys[Cheat::Walls][0] = KEY_F11;
342 312 cheatkeys[Cheat::Fast][0] = KEY_Q;
343 312 cheatkeys[Cheat::Light][0] = KEY_L;
344 312 cheatkeys[Cheat::IgnoreSideView][0] = KEY_V;
345 312 cheatkeys[Cheat::Kill][0] = KEY_K;
346 312 cheatkeys[Cheat::GoTo][0] = KEY_G;
347 312 cheatkeys[Cheat::TrigSecrets][0] = KEY_S;
348 312 cheatkeys[Cheat::ShowL0][0] = KEY_0;
349 312 cheatkeys[Cheat::ShowL1][0] = KEY_1;
350 312 cheatkeys[Cheat::ShowL2][0] = KEY_2;
351 312 cheatkeys[Cheat::ShowL3][0] = KEY_3;
352 312 cheatkeys[Cheat::ShowL4][0] = KEY_4;
353 312 cheatkeys[Cheat::ShowL5][0] = KEY_5;
354 312 cheatkeys[Cheat::ShowL6][0] = KEY_6;
355 312 cheatkeys[Cheat::ShowFFC][0] = KEY_7;
356 312 cheatkeys[Cheat::ShowSprites][0] = KEY_8;
357 312 cheatkeys[Cheat::ShowWalkability][0] = KEY_W;
358 312 cheatkeys[Cheat::ShowEffects][0] = KEY_E;
359 312 cheatkeys[Cheat::ShowOverhead][0] = KEY_O;
360 312 cheatkeys[Cheat::ShowPushblock][0] = KEY_P;
361 312 cheatkeys[Cheat::ShowHitbox][0] = KEY_C;
362 312 cheatkeys[Cheat::ShowFFCScripts][0] = KEY_F;
363 312 }
364
365 static bool loaded_game_configs;
366
367 312 void load_game_configs()
368 {
369 312 loaded_game_configs = true;
370 312 joystick_index = zc_get_config(ctrl_sect,"joystick_index",0);
371 312 js_stick_1_x_stick = zc_get_config(ctrl_sect,"js_stick_1_x_stick",0);
372 312 js_stick_1_x_axis = zc_get_config(ctrl_sect,"js_stick_1_x_axis",0);
373 312 js_stick_1_x_offset = zc_get_config(ctrl_sect,"js_stick_1_x_offset",0) ? 128 : 0;
374 312 js_stick_1_y_stick = zc_get_config(ctrl_sect,"js_stick_1_y_stick",0);
375 312 js_stick_1_y_axis = zc_get_config(ctrl_sect,"js_stick_1_y_axis",1);
376 312 js_stick_1_y_offset = zc_get_config(ctrl_sect,"js_stick_1_y_offset",0) ? 128 : 0;
377 312 js_stick_2_x_stick = zc_get_config(ctrl_sect,"js_stick_2_x_stick",1);
378 312 js_stick_2_x_axis = zc_get_config(ctrl_sect,"js_stick_2_x_axis",0);
379 312 js_stick_2_x_offset = zc_get_config(ctrl_sect,"js_stick_2_x_offset",0) ? 128 : 0;
380 312 js_stick_2_y_stick = zc_get_config(ctrl_sect,"js_stick_2_y_stick",1);
381 312 js_stick_2_y_axis = zc_get_config(ctrl_sect,"js_stick_2_y_axis",1);
382 312 js_stick_2_y_offset = zc_get_config(ctrl_sect,"js_stick_2_y_offset",0) ? 128 : 0;
383 312 analog_movement = (zc_get_config(ctrl_sect,"analog_movement",1));
384
385 //cheat modifier keya
386 312 cheat_modifier_keys[0] = zc_get_config(ctrl_sect,"key_cheatmod_a1",KEY_ZC_LCONTROL);
387 312 cheat_modifier_keys[1] = zc_get_config(ctrl_sect,"key_cheatmod_a2",0);
388 312 cheat_modifier_keys[2] = zc_get_config(ctrl_sect,"key_cheatmod_b1",KEY_ZC_RCONTROL);
389 312 cheat_modifier_keys[3] = zc_get_config(ctrl_sect,"key_cheatmod_b2",0);
390
391 //cheat keys
392 312 load_default_cheatkeys();
393 char buf[256];
394
2/2
✓ Branch 0 taken 312 times.
✓ Branch 1 taken 11232 times.
11544 for(size_t q = 1; q < Cheat::Last; ++q)
395 {
396
1/2
✓ Branch 0 taken 11232 times.
✗ Branch 1 not taken.
11232 if(!bindable_cheat((Cheat)q)) continue;
397 11232 std::string cheatname = cheat_to_string((Cheat)q);
398
1/2
✓ Branch 0 taken 11232 times.
✗ Branch 1 not taken.
11232 util::lowerstr(cheatname);
399 11232 sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
400
1/2
✓ Branch 0 taken 11232 times.
✗ Branch 1 not taken.
11232 cheatkeys[q][0] = zc_get_config(ctrl_sect,buf,cheatkeys[q][0]);
401 11232 sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
402
1/2
✓ Branch 0 taken 11232 times.
✗ Branch 1 not taken.
11232 cheatkeys[q][1] = zc_get_config(ctrl_sect,buf,cheatkeys[q][1]);
403 11232 }
404
405
1/2
✓ Branch 0 taken 312 times.
✗ Branch 1 not taken.
312 if((uint32_t)joystick_index >= MAX_JOYSTICKS)
406 joystick_index = 0;
407
408 312 Akey = zc_get_config(ctrl_sect,"key_a",KEY_Z);
409 312 Bkey = zc_get_config(ctrl_sect,"key_b",KEY_X);
410 312 Skey = zc_get_config(ctrl_sect,"key_s",KEY_ENTER);
411 312 Lkey = zc_get_config(ctrl_sect,"key_l",KEY_Q);
412 312 Rkey = zc_get_config(ctrl_sect,"key_r",KEY_W);
413 312 Pkey = zc_get_config(ctrl_sect,"key_p",KEY_SPACE);
414 312 Exkey1 = zc_get_config(ctrl_sect,"key_ex1",KEY_A);
415 312 Exkey2 = zc_get_config(ctrl_sect,"key_ex2",KEY_S);
416 312 Exkey3 = zc_get_config(ctrl_sect,"key_ex3",KEY_D);
417 312 Exkey4 = zc_get_config(ctrl_sect,"key_ex4",KEY_C);
418
419 312 DUkey = zc_get_config(ctrl_sect,"key_up", KEY_UP);
420 312 DDkey = zc_get_config(ctrl_sect,"key_down", KEY_DOWN);
421 312 DLkey = zc_get_config(ctrl_sect,"key_left", KEY_LEFT);
422 312 DRkey = zc_get_config(ctrl_sect,"key_right",KEY_RIGHT);
423
424 312 Abtn = zc_get_config(ctrl_sect,"btn_a",2);
425 312 Bbtn = zc_get_config(ctrl_sect,"btn_b",1);
426 312 Sbtn = zc_get_config(ctrl_sect,"btn_s",10);
427 312 Mbtn = zc_get_config(ctrl_sect,"btn_m",9);
428 312 Lbtn = zc_get_config(ctrl_sect,"btn_l",5);
429 312 Rbtn = zc_get_config(ctrl_sect,"btn_r",6);
430 312 Pbtn = zc_get_config(ctrl_sect,"btn_p",12);
431 312 Exbtn1 = zc_get_config(ctrl_sect,"btn_ex1",7);
432 312 Exbtn2 = zc_get_config(ctrl_sect,"btn_ex2",8);
433 312 Exbtn3 = zc_get_config(ctrl_sect,"btn_ex3",4);
434 312 Exbtn4 = zc_get_config(ctrl_sect,"btn_ex4",3);
435
436 312 DUbtn = zc_get_config(ctrl_sect,"btn_up",13);
437 312 DDbtn = zc_get_config(ctrl_sect,"btn_down",14);
438 312 DLbtn = zc_get_config(ctrl_sect,"btn_left",15);
439 312 DRbtn = zc_get_config(ctrl_sect,"btn_right",16);
440
441 312 epilepsyFlashReduction = zc_get_config(cfg_sect,"epilepsy_flash_reduction",0);
442
443 312 midi_volume = zc_get_config(sfx_sect,"midi",255);
444 312 sfx_volume = zc_get_config(sfx_sect,"sfx",255);
445 312 emusic_volume = zc_get_config(sfx_sect,"emusic",255);
446 312 pan_style = zc_get_config(sfx_sect,"pan",1);
447 312 volkeys = zc_get_config(sfx_sect,"volkeys",0)!=0;
448 312 zc_vsync = zc_get_config(cfg_sect,"vsync",0);
449 312 Throttlefps = zc_get_config(cfg_sect,"throttlefps",1)!=0;
450 312 Maxfps = zc_get_config(cfg_sect,"maxfps",0);
451 312 TransLayers = zc_get_config(cfg_sect,"translayers",1)!=0;
452 312 SnapshotFormat = zc_get_config(cfg_sect,"snapshot_format",3);
453 312 ShowBottomPixels = zc_get_config(cfg_sect,"bottom_8_px",0);
454 312 SnapshotScale = zc_get_config(cfg_sect,"snapshot_scale",2);
455 312 NameEntryMode = zc_get_config(cfg_sect,"name_entry_mode",0);
456 #ifdef __EMSCRIPTEN__
457 if (em_is_mobile()) NameEntryMode = 2;
458 #endif
459 312 ShowFPS = zc_get_config(cfg_sect,"showfps",0)!=0;
460 312 ShowGameTime = zc_get_config(cfg_sect,"showtime",0);
461 312 NESquit = zc_get_config(cfg_sect,"fastquit",0)!=0;
462 312 ClickToFreeze = zc_get_config(cfg_sect,"clicktofreeze",1)!=0;
463 312 abc_patternmatch = zc_get_config(cfg_sect, "lister_pattern_matching", 1);
464 312 pause_in_background = zc_get_config(cfg_sect, "pause_in_background", 0);
465
466 312 window_width = resx = zc_get_config(cfg_sect,"window_width",-1);
467 312 window_height = resy = zc_get_config(cfg_sect,"window_height",-1);
468 312 SaveDragResize = zc_get_config(cfg_sect,"save_drag_resize",0)!=0;
469 312 DragAspect = zc_get_config(cfg_sect,"drag_aspect",0)!=0;
470 312 SaveWinPos = zc_get_config(cfg_sect,"save_window_position",0)!=0;
471 312 scaleForceInteger = zc_get_config("zeldadx","scaling_force_integer",1)!=0;
472 312 stretchGame = zc_get_config("zeldadx","stretch_game_area",0)!=0;
473
474 312 loadlast = zc_get_config(cfg_sect,"load_last",0);
475
476 312 fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
477
478 312 info_opacity = zc_get_config("zc","debug_info_opacity",255);
479 #ifdef _WIN32
480 console_enabled = (byte) zc_get_config("CONSOLE", "enabled", 0);
481 //use_win7_keyboard_fix = (byte) zc_get_config(cfg_sect,"use_win7_key_fix",0);
482 use_win32_proc = (byte) zc_get_config(cfg_sect,"zc_win_proc_fix",0); //buggy
483
484 // This one's for Aero
485 use_dwm_flush = (byte) zc_get_config("zeldadx","use_dwm_flush",0);
486
487 monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
488 #else //UNIX
489 312 console_enabled = (byte) zc_get_config("CONSOLE", "enabled", 0);
490 312 monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
491 #endif
492 312 clearConsoleOnLoad = zc_get_config("CONSOLE","clear_console_on_load",1)!=0;
493 312 clearConsoleOnReload = zc_get_config("CONSOLE","clear_console_on_reload",0)!=0;
494
495 312 strcpy(qstdir,zc_get_config(cfg_sect,"quest_dir","quests"));
496 312 strcpy(qstpath,qstdir); //qstpath is the local (for this run of ZC) quest path, qstdir is the universal quest dir.
497 312 ss_enable = zc_get_config(cfg_sect,"ss_enable",1) ? 1 : 0;
498 312 ss_after = vbound(zc_get_config(cfg_sect,"ss_after",14), 0, 14);
499 312 ss_speed = vbound(zc_get_config(cfg_sect,"ss_speed",2), 0, 6);
500 312 ss_density = vbound(zc_get_config(cfg_sect,"ss_density",3), 0, 6);
501 312 heart_beep = zc_get_config(cfg_sect,"heart_beep",0)!=0;
502 //gui_colorset = zc_get_config(cfg_sect,"gui_colorset",0);
503 312 sfxdat = zc_get_config(cfg_sect,"use_sfx_dat",1); // TODO: sfxdat is always set to 1 for titlescreen... and 0 in readsfx... so this cfg is pointless, remove?
504 312 fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
505 312 use_save_indicator = zc_get_config(cfg_sect,"save_indicator",0);
506 312 zc_192b163_warp_compatibility = zc_get_config(cfg_sect,"zc_192b163_warp_compatibility",0);
507 312 SkipTitle = zc_get_config(cfg_sect,"skip_title",0);
508 312 }
509
510 void save_control_configs(bool kb)
511 {
512 if(kb)
513 {
514 zc_set_config(ctrl_sect,"key_cheatmod_a1",cheat_modifier_keys[0]);
515 zc_set_config(ctrl_sect,"key_cheatmod_a2",cheat_modifier_keys[1]);
516 zc_set_config(ctrl_sect,"key_cheatmod_b1",cheat_modifier_keys[2]);
517 zc_set_config(ctrl_sect,"key_cheatmod_b2",cheat_modifier_keys[3]);
518
519 if (!replay_is_replaying())
520 {
521 zc_set_config(ctrl_sect,"key_a",Akey);
522 zc_set_config(ctrl_sect,"key_b",Bkey);
523 zc_set_config(ctrl_sect,"key_s",Skey);
524 zc_set_config(ctrl_sect,"key_l",Lkey);
525 zc_set_config(ctrl_sect,"key_r",Rkey);
526 zc_set_config(ctrl_sect,"key_p",Pkey);
527 zc_set_config(ctrl_sect,"key_ex1",Exkey1);
528 zc_set_config(ctrl_sect,"key_ex2",Exkey2);
529 zc_set_config(ctrl_sect,"key_ex3",Exkey3);
530 zc_set_config(ctrl_sect,"key_ex4",Exkey4);
531 zc_set_config(ctrl_sect,"key_up", DUkey);
532 zc_set_config(ctrl_sect,"key_down", DDkey);
533 zc_set_config(ctrl_sect,"key_left", DLkey);
534 zc_set_config(ctrl_sect,"key_right",DRkey);
535 }
536 }
537 else
538 {
539 zc_set_config(ctrl_sect,"joystick_index",joystick_index);
540 zc_set_config(ctrl_sect,"js_stick_1_x_stick",js_stick_1_x_stick);
541 zc_set_config(ctrl_sect,"js_stick_1_x_axis",js_stick_1_x_axis);
542 zc_set_config(ctrl_sect,"js_stick_1_x_offset",js_stick_1_x_offset ? 1 : 0);
543 zc_set_config(ctrl_sect,"js_stick_1_y_stick",js_stick_1_y_stick);
544 zc_set_config(ctrl_sect,"js_stick_1_y_axis",js_stick_1_y_axis);
545 zc_set_config(ctrl_sect,"js_stick_1_y_offset",js_stick_1_y_offset ? 1 : 0);
546 zc_set_config(ctrl_sect,"js_stick_2_x_stick",js_stick_2_x_stick);
547 zc_set_config(ctrl_sect,"js_stick_2_x_axis",js_stick_2_x_axis);
548 zc_set_config(ctrl_sect,"js_stick_2_x_offset",js_stick_2_x_offset ? 1 : 0);
549 zc_set_config(ctrl_sect,"js_stick_2_y_stick",js_stick_2_y_stick);
550 zc_set_config(ctrl_sect,"js_stick_2_y_axis",js_stick_2_y_axis);
551 zc_set_config(ctrl_sect,"js_stick_2_y_offset",js_stick_2_y_offset ? 1 : 0);
552 zc_set_config(ctrl_sect,"analog_movement",analog_movement);
553
554 zc_set_config(ctrl_sect,"btn_a",Abtn);
555 zc_set_config(ctrl_sect,"btn_b",Bbtn);
556 zc_set_config(ctrl_sect,"btn_s",Sbtn);
557 zc_set_config(ctrl_sect,"btn_m",Mbtn);
558 zc_set_config(ctrl_sect,"btn_l",Lbtn);
559 zc_set_config(ctrl_sect,"btn_r",Rbtn);
560 zc_set_config(ctrl_sect,"btn_p",Pbtn);
561 zc_set_config(ctrl_sect,"btn_ex1",Exbtn1);
562 zc_set_config(ctrl_sect,"btn_ex2",Exbtn2);
563 zc_set_config(ctrl_sect,"btn_ex3",Exbtn3);
564 zc_set_config(ctrl_sect,"btn_ex4",Exbtn4);
565
566 zc_set_config(ctrl_sect,"btn_up",DUbtn);
567 zc_set_config(ctrl_sect,"btn_down",DDbtn);
568 zc_set_config(ctrl_sect,"btn_left",DLbtn);
569 zc_set_config(ctrl_sect,"btn_right",DRbtn);
570 }
571 }
572
573 void save_cheatkeys()
574 {
575 char buf[256];
576 for(size_t q = 1; q < Cheat::Last; ++q)
577 {
578 if(!bindable_cheat((Cheat)q)) continue;
579 std::string cheatname = cheat_to_string((Cheat)q);
580 util::lowerstr(cheatname);
581 sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
582 zc_set_config(ctrl_sect,buf,cheatkeys[q][0]);
583 sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
584 if(cheatkeys[q][1])
585 zc_set_config(ctrl_sect,buf,cheatkeys[q][1]);
586 else zc_set_config(ctrl_sect,buf,(char*)nullptr);
587 }
588 }
589
590 312 void save_game_configs()
591 {
592
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 312 times.
312 if (!loaded_game_configs) return;
593
594 312 packfile_password("");
595
596
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 312 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
312 if (all_get_display() && !all_get_fullscreen_flag()&& SaveWinPos)
597 {
598 int o_window_x, o_window_y;
599 al_get_window_position(all_get_display(), &o_window_x, &o_window_y);
600 zc_set_config(cfg_sect,"window_x",o_window_x);
601 zc_set_config(cfg_sect,"window_y",o_window_y);
602 }
603
604
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 312 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
312 if (all_get_display() && !all_get_fullscreen_flag() && SaveDragResize)
605 {
606 window_width = al_get_display_width(all_get_display());
607 window_height = al_get_display_height(all_get_display());
608 zc_set_config(cfg_sect,"window_width",window_width);
609 zc_set_config(cfg_sect,"window_height",window_height);
610 }
611
612 312 zc_set_config(cfg_sect,"load_last",loadlast);
613 312 zc_set_config(cfg_sect,"use_sfx_dat",sfxdat);
614
615 312 flush_config_file();
616 #ifdef __EMSCRIPTEN__
617 em_sync_fs();
618 #endif
619 312 }
620
621 //----------------------------------------------------------------
622
623 // Timers
624
625 41367 void fps_callback()
626 {
627 41367 lastfps=framecnt;
628 41367 framecnt=0;
629 41367 }
630
631 END_OF_FUNCTION(fps_callback)
632
633 312 int32_t Z_init_timers()
634 {
635 static bool didit = false;
636 const static char *err_str = "Couldn't allocate timer";
637 312 err_str = err_str; //Unused variable warning
638
639
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 312 times.
312 if(didit)
640 return 1;
641
642 312 didit = true;
643
644 LOCK_VARIABLE(lastfps);
645 LOCK_VARIABLE(framecnt);
646 LOCK_FUNCTION(fps_callback);
647
648
1/2
✓ Branch 0 taken 312 times.
✗ Branch 1 not taken.
312 if(install_int_ex(fps_callback,SECS_TO_TIMER(1)))
649 return 0;
650
651 312 return 1;
652 312 }
653
654 312 void Z_remove_timers()
655 {
656 312 remove_int(fps_callback);
657 312 }
658
659 //----------------------------------------------------------------
660
661 void go()
662 {
663 blit(screen,tmp_scr,scrx,scry,0,0,screen->w,screen->h);
664 }
665
666 void comeback()
667 {
668 blit(tmp_scr,screen,0,0,scrx,scry,screen->w,screen->h);
669 }
670
671 void dump_pal(BITMAP *dest)
672 {
673 for(int32_t i=0; i<256; i++)
674 rectfill(dest,(i&63)<<2,(i&0xFC0)>>4,((i&63)<<2)+3,((i&0xFC0)>>4)+3,i);
675 }
676
677 //----------------------------------------------------------------
678
679 int game_mouse_index = ZCM_BLANK;
680 static bool system_mouse = false;
681 92 bool sys_mouse()
682 {
683 92 system_mouse = true;
684 92 return MouseSprite::set(ZCM_NORMAL);
685 }
686 1616 bool game_mouse()
687 {
688 1616 system_mouse = false;
689 1616 return MouseSprite::set(game_mouse_index);
690 }
691 void custom_mouse(BITMAP* bmp, int fx, int fy, bool sys_recolor, bool user_scale)
692 {
693 if(!bmp)
694 return;
695 float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
696 int scaledw = bmp->w*scale, scaledh = bmp->h*scale;
697 if(bmp->w == scaledw && bmp->h == scaledh)
698 user_scale = false;
699 if(user_scale || sys_recolor)
700 {
701 if(!user_scale) scale = 1;
702 BITMAP* tmpbmp = create_bitmap_ex(8,bmp->w*scale,bmp->h*scale);
703 if(user_scale)
704 stretch_blit(bmp, tmpbmp, 0, 0, bmp->w, bmp->h, 0, 0, tmpbmp->w, tmpbmp->h);
705 else
706 blit(bmp, tmpbmp, 0, 0, 0, 0, bmp->w, bmp->h);
707 if(sys_recolor)
708 recolor_mouse(tmpbmp);
709 MouseSprite::assign(ZCM_CUSTOM, tmpbmp, fx*scale, fy*scale);
710 destroy_bitmap(tmpbmp);
711 }
712 else
713 {
714 MouseSprite::assign(ZCM_CUSTOM, bmp, fx, fy);
715 }
716 }
717
718 //Handles converting the mouse sprite from the .dat file
719 void recolor_mouse(BITMAP* bmp)
720 {
721 for(int32_t x = 0; x < bmp->w; ++x)
722 {
723 for(int32_t y = 0; y < bmp->h; ++y)
724 {
725 int32_t color = getpixel(bmp, x, y);
726 switch(color)
727 {
728 case dvc(1):
729 color = jwin_pal[jcCURSORMISC];
730 break;
731 case dvc(2):
732 color = jwin_pal[jcCURSOROUTLINE];
733 break;
734 case dvc(3):
735 color = jwin_pal[jcCURSORLIGHT];
736 break;
737 case dvc(5):
738 color = jwin_pal[jcCURSORDARK];
739 break;
740 default:
741 continue;
742 }
743 putpixel(bmp, x, y, color);
744 }
745 }
746 }
747 void load_mouse()
748 {
749 PALETTE pal;
750 BITMAP* cursor_bitmap = load_bitmap("assets/cursor.bmp", pal);
751 if (!cursor_bitmap)
752 Z_error_fatal("Missing required file %s\n", "assets/cursor.bmp");
753
754 enter_sys_pal();
755 MouseSprite::set(-1);
756 float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
757 int32_t sz = 16*scale;
758 for(int32_t j = 0; j < 1; ++j)
759 {
760 BITMAP* tmpbmp = create_bitmap_ex(8,16,16);
761 if(zcmouse[j])
762 destroy_bitmap(zcmouse[j]);
763 zcmouse[j] = create_bitmap_ex(8,sz,sz);
764 clear_bitmap(zcmouse[j]);
765 clear_bitmap(tmpbmp);
766 blit(cursor_bitmap,tmpbmp,1,j*17+1,0,0,16,16);
767 recolor_mouse(tmpbmp);
768 if(sz!=16)
769 stretch_blit(tmpbmp, zcmouse[j], 0, 0, 16, 16, 0, 0, sz, sz);
770 else
771 blit(tmpbmp, zcmouse[j], 0, 0, 0, 0, 16, 16);
772 destroy_bitmap(tmpbmp);
773 }
774 if(!hw_palette) hw_palette = &RAMpal;
775 zc_set_palette(*hw_palette);
776
777 BITMAP* blankmouse = create_bitmap_ex(8,16,16);
778 clear_bitmap(blankmouse);
779
780 MouseSprite::assign(ZCM_NORMAL, zcmouse[0], 1*scale, 1*scale);
781 MouseSprite::assign(ZCM_BLANK, blankmouse);
782 //Don't assign ZCM_CUSTOM. That'll be handled by scripts.
783
784 //Reload the mouse
785 if(system_mouse)
786 sys_mouse();
787 else game_mouse();
788
789 destroy_bitmap(blankmouse);
790 destroy_bitmap(cursor_bitmap);
791 exit_sys_pal();
792 }
793
794 // sets the video mode and initializes the palette and mouse sprite
795 312 bool game_vid_mode(int32_t mode,int32_t wait)
796 {
797
1/2
✓ Branch 0 taken 312 times.
✗ Branch 1 not taken.
312 if (is_headless())
798 312 return true;
799
800 extern int zq_screen_w, zq_screen_h;
801 if(set_gfx_mode(mode,resx,resy,zq_screen_w,zq_screen_h)!=0)
802 {
803 return false;
804 }
805
806 scrx = (resx-320)>>1;
807 scry = (resy-240)>>1;
808 for(int32_t q = 0; q < NUM_ZCMOUSE; ++q)
809 zcmouse[q] = NULL;
810 load_mouse();
811
812 for(int32_t i=240; i<256; i++)
813 RAMpal[i]=pal_gui[i];
814
815 zc_set_palette(RAMpal);
816 clear_to_color(screen,BLACK);
817
818 rest(wait);
819 return true;
820 312 }
821
822 320 void null_quest()
823 {
824
1/2
✓ Branch 0 taken 320 times.
✗ Branch 1 not taken.
320 std::string title_assets_path = "modules/classic/title_gfx.dat";
825
2/4
✓ Branch 0 taken 320 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 320 times.
320 if (get_last_loaded_qstpath() == title_assets_path)
826 return;
827
828 byte skip_flags[4];
829
2/2
✓ Branch 0 taken 320 times.
✓ Branch 1 taken 8320 times.
8640 for (int i = 0; i < skip_max; i++)
830
1/2
✓ Branch 0 taken 8320 times.
✗ Branch 1 not taken.
8320 set_bit(skip_flags, i, 1);
831
1/2
✓ Branch 0 taken 320 times.
✗ Branch 1 not taken.
320 set_bit(skip_flags, skip_tiles, 0);
832
1/2
✓ Branch 0 taken 320 times.
✗ Branch 1 not taken.
320 set_bit(skip_flags, skip_csets, 0);
833
1/2
✓ Branch 0 taken 320 times.
✗ Branch 1 not taken.
320 set_bit(skip_flags, skip_misc, 0); // needed for miscsfx (skip this and `tests/replays/demons_inferno/demons_inferno_1_of_2.zplay` fails).
834
1/2
✓ Branch 0 taken 320 times.
✗ Branch 1 not taken.
320 loadquest(title_assets_path.c_str(), &QHeader, &QMisc, tunes+ZC_MIDI_COUNT, false, skip_flags, 0, false);
835 320 sfxdat = 1;
836 // TODO: sfx.dat is ~1.2 MB. Could be better to break that up into individual files and load on demand / not at startup.
837 // TODO: can we cache the tiles/colordata so we don't have to read title_gfx.dat more than once?
838 // colordata is tiny, but tilebuf is huge, so limit that to just what the title screen needs.
839 // Another option: embed this data into the binary (`xxd -i resources/modules/classic/title_gfx.dat > title_gfx.h`)
840
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 320 times.
320 }
841
842 320 void init_NES_mode()
843 {
844 320 null_quest();
845 320 }
846
847 //----------------------------------------------------------------
848
849 qword trianglelines[16]=
850 {
851 0x0000000000000000ULL,
852 0xFD00000000000000ULL,
853 0xFDFD000000000000ULL,
854 0xFDFDFD0000000000ULL,
855 0xFDFDFDFD00000000ULL,
856 0xFDFDFDFDFD000000ULL,
857 0xFDFDFDFDFDFD0000ULL,
858 0xFDFDFDFDFDFDFD00ULL,
859 0xFDFDFDFDFDFDFDFDULL,
860 0x00FDFDFDFDFDFDFDULL,
861 0x0000FDFDFDFDFDFDULL,
862 0x000000FDFDFDFDFDULL,
863 0x00000000FDFDFDFDULL,
864 0x0000000000FDFDFDULL,
865 0x000000000000FDFDULL,
866 0x00000000000000FDULL,
867 };
868
869 word screen_triangles[29][32];
870
871 // the ULL suffixes are to prevent this warning:
872 // warning: integer constant is too large for "int32_t" type
873
874 qword triangles[4][16][8]= //[direction][value][line]
875 {
876 {
877 {
878 0x0000000000000000ULL,
879 0x0000000000000000ULL,
880 0x0000000000000000ULL,
881 0x0000000000000000ULL,
882 0x0000000000000000ULL,
883 0x0000000000000000ULL,
884 0x0000000000000000ULL,
885 0x0000000000000000ULL
886 },
887 {
888 0xFD00000000000000ULL,
889 0x0000000000000000ULL,
890 0x0000000000000000ULL,
891 0x0000000000000000ULL,
892 0x0000000000000000ULL,
893 0x0000000000000000ULL,
894 0x0000000000000000ULL,
895 0x0000000000000000ULL
896 },
897 {
898 0xFDFD000000000000ULL,
899 0xFD00000000000000ULL,
900 0x0000000000000000ULL,
901 0x0000000000000000ULL,
902 0x0000000000000000ULL,
903 0x0000000000000000ULL,
904 0x0000000000000000ULL,
905 0x0000000000000000ULL
906 },
907 {
908 0xFDFDFD0000000000ULL,
909 0xFDFD000000000000ULL,
910 0xFD00000000000000ULL,
911 0x0000000000000000ULL,
912 0x0000000000000000ULL,
913 0x0000000000000000ULL,
914 0x0000000000000000ULL,
915 0x0000000000000000ULL
916 },
917 {
918 0xFDFDFDFD00000000ULL,
919 0xFDFDFD0000000000ULL,
920 0xFDFD000000000000ULL,
921 0xFD00000000000000ULL,
922 0x0000000000000000ULL,
923 0x0000000000000000ULL,
924 0x0000000000000000ULL,
925 0x0000000000000000ULL
926 },
927 {
928 0xFDFDFDFDFD000000ULL,
929 0xFDFDFDFD00000000ULL,
930 0xFDFDFD0000000000ULL,
931 0xFDFD000000000000ULL,
932 0xFD00000000000000ULL,
933 0x0000000000000000ULL,
934 0x0000000000000000ULL,
935 0x0000000000000000ULL
936 },
937 {
938 0xFDFDFDFDFDFD0000ULL,
939 0xFDFDFDFDFD000000ULL,
940 0xFDFDFDFD00000000ULL,
941 0xFDFDFD0000000000ULL,
942 0xFDFD000000000000ULL,
943 0xFD00000000000000ULL,
944 0x0000000000000000ULL,
945 0x0000000000000000ULL
946 },
947 {
948 0xFDFDFDFDFDFDFD00ULL,
949 0xFDFDFDFDFDFD0000ULL,
950 0xFDFDFDFDFD000000ULL,
951 0xFDFDFDFD00000000ULL,
952 0xFDFDFD0000000000ULL,
953 0xFDFD000000000000ULL,
954 0xFD00000000000000ULL,
955 0x0000000000000000ULL
956 },
957 {
958 0xFDFDFDFDFDFDFDFDULL,
959 0xFDFDFDFDFDFDFD00ULL,
960 0xFDFDFDFDFDFD0000ULL,
961 0xFDFDFDFDFD000000ULL,
962 0xFDFDFDFD00000000ULL,
963 0xFDFDFD0000000000ULL,
964 0xFDFD000000000000ULL,
965 0xFD00000000000000ULL
966 },
967 {
968 0xFDFDFDFDFDFDFDFDULL,
969 0xFDFDFDFDFDFDFDFDULL,
970 0xFDFDFDFDFDFDFD00ULL,
971 0xFDFDFDFDFDFD0000ULL,
972 0xFDFDFDFDFD000000ULL,
973 0xFDFDFDFD00000000ULL,
974 0xFDFDFD0000000000ULL,
975 0xFDFD000000000000ULL
976 },
977 {
978 0xFDFDFDFDFDFDFDFDULL,
979 0xFDFDFDFDFDFDFDFDULL,
980 0xFDFDFDFDFDFDFDFDULL,
981 0xFDFDFDFDFDFDFD00ULL,
982 0xFDFDFDFDFDFD0000ULL,
983 0xFDFDFDFDFD000000ULL,
984 0xFDFDFDFD00000000ULL,
985 0xFDFDFD0000000000ULL
986 },
987 {
988 0xFDFDFDFDFDFDFDFDULL,
989 0xFDFDFDFDFDFDFDFDULL,
990 0xFDFDFDFDFDFDFDFDULL,
991 0xFDFDFDFDFDFDFDFDULL,
992 0xFDFDFDFDFDFDFD00ULL,
993 0xFDFDFDFDFDFD0000ULL,
994 0xFDFDFDFDFD000000ULL,
995 0xFDFDFDFD00000000ULL
996 },
997 {
998 0xFDFDFDFDFDFDFDFDULL,
999 0xFDFDFDFDFDFDFDFDULL,
1000 0xFDFDFDFDFDFDFDFDULL,
1001 0xFDFDFDFDFDFDFDFDULL,
1002 0xFDFDFDFDFDFDFDFDULL,
1003 0xFDFDFDFDFDFDFD00ULL,
1004 0xFDFDFDFDFDFD0000ULL,
1005 0xFDFDFDFDFD000000ULL
1006 },
1007 {
1008 0xFDFDFDFDFDFDFDFDULL,
1009 0xFDFDFDFDFDFDFDFDULL,
1010 0xFDFDFDFDFDFDFDFDULL,
1011 0xFDFDFDFDFDFDFDFDULL,
1012 0xFDFDFDFDFDFDFDFDULL,
1013 0xFDFDFDFDFDFDFDFDULL,
1014 0xFDFDFDFDFDFDFD00ULL,
1015 0xFDFDFDFDFDFD0000ULL
1016 },
1017 {
1018 0xFDFDFDFDFDFDFDFDULL,
1019 0xFDFDFDFDFDFDFDFDULL,
1020 0xFDFDFDFDFDFDFDFDULL,
1021 0xFDFDFDFDFDFDFDFDULL,
1022 0xFDFDFDFDFDFDFDFDULL,
1023 0xFDFDFDFDFDFDFDFDULL,
1024 0xFDFDFDFDFDFDFDFDULL,
1025 0xFDFDFDFDFDFDFD00ULL
1026 },
1027 {
1028 0xFDFDFDFDFDFDFDFDULL,
1029 0xFDFDFDFDFDFDFDFDULL,
1030 0xFDFDFDFDFDFDFDFDULL,
1031 0xFDFDFDFDFDFDFDFDULL,
1032 0xFDFDFDFDFDFDFDFDULL,
1033 0xFDFDFDFDFDFDFDFDULL,
1034 0xFDFDFDFDFDFDFDFDULL,
1035 0xFDFDFDFDFDFDFDFDULL
1036 }
1037 },
1038 {
1039 {
1040 0x0000000000000000ULL,
1041 0x0000000000000000ULL,
1042 0x0000000000000000ULL,
1043 0x0000000000000000ULL,
1044 0x0000000000000000ULL,
1045 0x0000000000000000ULL,
1046 0x0000000000000000ULL,
1047 0x0000000000000000ULL
1048 },
1049 {
1050 0x00000000000000FDULL,
1051 0x0000000000000000ULL,
1052 0x0000000000000000ULL,
1053 0x0000000000000000ULL,
1054 0x0000000000000000ULL,
1055 0x0000000000000000ULL,
1056 0x0000000000000000ULL,
1057 0x0000000000000000ULL
1058 },
1059 {
1060 0x000000000000FDFDULL,
1061 0x00000000000000FDULL,
1062 0x0000000000000000ULL,
1063 0x0000000000000000ULL,
1064 0x0000000000000000ULL,
1065 0x0000000000000000ULL,
1066 0x0000000000000000ULL,
1067 0x0000000000000000ULL
1068 },
1069 {
1070 0x0000000000FDFDFDULL,
1071 0x000000000000FDFDULL,
1072 0x00000000000000FDULL,
1073 0x0000000000000000ULL,
1074 0x0000000000000000ULL,
1075 0x0000000000000000ULL,
1076 0x0000000000000000ULL,
1077 0x0000000000000000ULL
1078 },
1079 {
1080 0x00000000FDFDFDFDULL,
1081 0x0000000000FDFDFDULL,
1082 0x000000000000FDFDULL,
1083 0x00000000000000FDULL,
1084 0x0000000000000000ULL,
1085 0x0000000000000000ULL,
1086 0x0000000000000000ULL,
1087 0x0000000000000000ULL
1088 },
1089 {
1090 0x000000FDFDFDFDFDULL,
1091 0x00000000FDFDFDFDULL,
1092 0x0000000000FDFDFDULL,
1093 0x000000000000FDFDULL,
1094 0x00000000000000FDULL,
1095 0x0000000000000000ULL,
1096 0x0000000000000000ULL,
1097 0x0000000000000000ULL
1098 },
1099 {
1100 0x0000FDFDFDFDFDFDULL,
1101 0x000000FDFDFDFDFDULL,
1102 0x00000000FDFDFDFDULL,
1103 0x0000000000FDFDFDULL,
1104 0x000000000000FDFDULL,
1105 0x00000000000000FDULL,
1106 0x0000000000000000ULL,
1107 0x0000000000000000ULL
1108 },
1109 {
1110 0x00FDFDFDFDFDFDFDULL,
1111 0x0000FDFDFDFDFDFDULL,
1112 0x000000FDFDFDFDFDULL,
1113 0x00000000FDFDFDFDULL,
1114 0x0000000000FDFDFDULL,
1115 0x000000000000FDFDULL,
1116 0x00000000000000FDULL,
1117 0x0000000000000000ULL
1118 },
1119 {
1120 0xFDFDFDFDFDFDFDFDULL,
1121 0x00FDFDFDFDFDFDFDULL,
1122 0x0000FDFDFDFDFDFDULL,
1123 0x000000FDFDFDFDFDULL,
1124 0x00000000FDFDFDFDULL,
1125 0x0000000000FDFDFDULL,
1126 0x000000000000FDFDULL,
1127 0x00000000000000FDULL
1128 },
1129 {
1130 0xFDFDFDFDFDFDFDFDULL,
1131 0xFDFDFDFDFDFDFDFDULL,
1132 0x00FDFDFDFDFDFDFDULL,
1133 0x0000FDFDFDFDFDFDULL,
1134 0x000000FDFDFDFDFDULL,
1135 0x00000000FDFDFDFDULL,
1136 0x0000000000FDFDFDULL,
1137 0x000000000000FDFDULL
1138 },
1139 {
1140 0xFDFDFDFDFDFDFDFDULL,
1141 0xFDFDFDFDFDFDFDFDULL,
1142 0xFDFDFDFDFDFDFDFDULL,
1143 0x00FDFDFDFDFDFDFDULL,
1144 0x0000FDFDFDFDFDFDULL,
1145 0x000000FDFDFDFDFDULL,
1146 0x00000000FDFDFDFDULL,
1147 0x0000000000FDFDFDULL
1148 },
1149 {
1150 0xFDFDFDFDFDFDFDFDULL,
1151 0xFDFDFDFDFDFDFDFDULL,
1152 0xFDFDFDFDFDFDFDFDULL,
1153 0xFDFDFDFDFDFDFDFDULL,
1154 0x00FDFDFDFDFDFDFDULL,
1155 0x0000FDFDFDFDFDFDULL,
1156 0x000000FDFDFDFDFDULL,
1157 0x00000000FDFDFDFDULL
1158 },
1159 {
1160 0xFDFDFDFDFDFDFDFDULL,
1161 0xFDFDFDFDFDFDFDFDULL,
1162 0xFDFDFDFDFDFDFDFDULL,
1163 0xFDFDFDFDFDFDFDFDULL,
1164 0xFDFDFDFDFDFDFDFDULL,
1165 0x00FDFDFDFDFDFDFDULL,
1166 0x0000FDFDFDFDFDFDULL,
1167 0x000000FDFDFDFDFDULL
1168 },
1169 {
1170 0xFDFDFDFDFDFDFDFDULL,
1171 0xFDFDFDFDFDFDFDFDULL,
1172 0xFDFDFDFDFDFDFDFDULL,
1173 0xFDFDFDFDFDFDFDFDULL,
1174 0xFDFDFDFDFDFDFDFDULL,
1175 0xFDFDFDFDFDFDFDFDULL,
1176 0x00FDFDFDFDFDFDFDULL,
1177 0x0000FDFDFDFDFDFDULL
1178 },
1179 {
1180 0xFDFDFDFDFDFDFDFDULL,
1181 0xFDFDFDFDFDFDFDFDULL,
1182 0xFDFDFDFDFDFDFDFDULL,
1183 0xFDFDFDFDFDFDFDFDULL,
1184 0xFDFDFDFDFDFDFDFDULL,
1185 0xFDFDFDFDFDFDFDFDULL,
1186 0xFDFDFDFDFDFDFDFDULL,
1187 0x00FDFDFDFDFDFDFDULL
1188 },
1189 {
1190 0xFDFDFDFDFDFDFDFDULL,
1191 0xFDFDFDFDFDFDFDFDULL,
1192 0xFDFDFDFDFDFDFDFDULL,
1193 0xFDFDFDFDFDFDFDFDULL,
1194 0xFDFDFDFDFDFDFDFDULL,
1195 0xFDFDFDFDFDFDFDFDULL,
1196 0xFDFDFDFDFDFDFDFDULL,
1197 0xFDFDFDFDFDFDFDFDULL
1198 }
1199 },
1200 {
1201 {
1202 0x0000000000000000ULL,
1203 0x0000000000000000ULL,
1204 0x0000000000000000ULL,
1205 0x0000000000000000ULL,
1206 0x0000000000000000ULL,
1207 0x0000000000000000ULL,
1208 0x0000000000000000ULL,
1209 0x0000000000000000ULL
1210 },
1211 {
1212 0x0000000000000000ULL,
1213 0x0000000000000000ULL,
1214 0x0000000000000000ULL,
1215 0x0000000000000000ULL,
1216 0x0000000000000000ULL,
1217 0x0000000000000000ULL,
1218 0x0000000000000000ULL,
1219 0xFD00000000000000ULL
1220 },
1221 {
1222 0x0000000000000000ULL,
1223 0x0000000000000000ULL,
1224 0x0000000000000000ULL,
1225 0x0000000000000000ULL,
1226 0x0000000000000000ULL,
1227 0x0000000000000000ULL,
1228 0xFD00000000000000ULL,
1229 0xFDFD000000000000ULL
1230 },
1231 {
1232 0x0000000000000000ULL,
1233 0x0000000000000000ULL,
1234 0x0000000000000000ULL,
1235 0x0000000000000000ULL,
1236 0x0000000000000000ULL,
1237 0xFD00000000000000ULL,
1238 0xFDFD000000000000ULL,
1239 0xFDFDFD0000000000ULL
1240 },
1241 {
1242 0x0000000000000000ULL,
1243 0x0000000000000000ULL,
1244 0x0000000000000000ULL,
1245 0x0000000000000000ULL,
1246 0xFD00000000000000ULL,
1247 0xFDFD000000000000ULL,
1248 0xFDFDFD0000000000ULL,
1249 0xFDFDFDFD00000000ULL
1250 },
1251 {
1252 0x0000000000000000ULL,
1253 0x0000000000000000ULL,
1254 0x0000000000000000ULL,
1255 0xFD00000000000000ULL,
1256 0xFDFD000000000000ULL,
1257 0xFDFDFD0000000000ULL,
1258 0xFDFDFDFD00000000ULL,
1259 0xFDFDFDFDFD000000ULL
1260 },
1261 {
1262 0x0000000000000000ULL,
1263 0x0000000000000000ULL,
1264 0xFD00000000000000ULL,
1265 0xFDFD000000000000ULL,
1266 0xFDFDFD0000000000ULL,
1267 0xFDFDFDFD00000000ULL,
1268 0xFDFDFDFDFD000000ULL,
1269 0xFDFDFDFDFDFD0000ULL
1270 },
1271 {
1272 0x0000000000000000ULL,
1273 0xFD00000000000000ULL,
1274 0xFDFD000000000000ULL,
1275 0xFDFDFD0000000000ULL,
1276 0xFDFDFDFD00000000ULL,
1277 0xFDFDFDFDFD000000ULL,
1278 0xFDFDFDFDFDFD0000ULL,
1279 0xFDFDFDFDFDFDFD00ULL
1280 },
1281 {
1282 0xFD00000000000000ULL,
1283 0xFDFD000000000000ULL,
1284 0xFDFDFD0000000000ULL,
1285 0xFDFDFDFD00000000ULL,
1286 0xFDFDFDFDFD000000ULL,
1287 0xFDFDFDFDFDFD0000ULL,
1288 0xFDFDFDFDFDFDFD00ULL,
1289 0xFDFDFDFDFDFDFDFDULL
1290 },
1291 {
1292 0xFDFD000000000000ULL,
1293 0xFDFDFD0000000000ULL,
1294 0xFDFDFDFD00000000ULL,
1295 0xFDFDFDFDFD000000ULL,
1296 0xFDFDFDFDFDFD0000ULL,
1297 0xFDFDFDFDFDFDFD00ULL,
1298 0xFDFDFDFDFDFDFDFDULL,
1299 0xFDFDFDFDFDFDFDFDULL
1300 },
1301 {
1302 0xFDFDFD0000000000ULL,
1303 0xFDFDFDFD00000000ULL,
1304 0xFDFDFDFDFD000000ULL,
1305 0xFDFDFDFDFDFD0000ULL,
1306 0xFDFDFDFDFDFDFD00ULL,
1307 0xFDFDFDFDFDFDFDFDULL,
1308 0xFDFDFDFDFDFDFDFDULL,
1309 0xFDFDFDFDFDFDFDFDULL
1310 },
1311 {
1312 0xFDFDFDFD00000000ULL,
1313 0xFDFDFDFDFD000000ULL,
1314 0xFDFDFDFDFDFD0000ULL,
1315 0xFDFDFDFDFDFDFD00ULL,
1316 0xFDFDFDFDFDFDFDFDULL,
1317 0xFDFDFDFDFDFDFDFDULL,
1318 0xFDFDFDFDFDFDFDFDULL,
1319 0xFDFDFDFDFDFDFDFDULL
1320 },
1321 {
1322 0xFDFDFDFDFD000000ULL,
1323 0xFDFDFDFDFDFD0000ULL,
1324 0xFDFDFDFDFDFDFD00ULL,
1325 0xFDFDFDFDFDFDFDFDULL,
1326 0xFDFDFDFDFDFDFDFDULL,
1327 0xFDFDFDFDFDFDFDFDULL,
1328 0xFDFDFDFDFDFDFDFDULL,
1329 0xFDFDFDFDFDFDFDFDULL
1330 },
1331 {
1332 0xFDFDFDFDFDFD0000ULL,
1333 0xFDFDFDFDFDFDFD00ULL,
1334 0xFDFDFDFDFDFDFDFDULL,
1335 0xFDFDFDFDFDFDFDFDULL,
1336 0xFDFDFDFDFDFDFDFDULL,
1337 0xFDFDFDFDFDFDFDFDULL,
1338 0xFDFDFDFDFDFDFDFDULL,
1339 0xFDFDFDFDFDFDFDFDULL
1340 },
1341 {
1342 0xFDFDFDFDFDFDFD00ULL,
1343 0xFDFDFDFDFDFDFDFDULL,
1344 0xFDFDFDFDFDFDFDFDULL,
1345 0xFDFDFDFDFDFDFDFDULL,
1346 0xFDFDFDFDFDFDFDFDULL,
1347 0xFDFDFDFDFDFDFDFDULL,
1348 0xFDFDFDFDFDFDFDFDULL,
1349 0xFDFDFDFDFDFDFDFDULL
1350 },
1351 {
1352 0xFDFDFDFDFDFDFDFDULL,
1353 0xFDFDFDFDFDFDFDFDULL,
1354 0xFDFDFDFDFDFDFDFDULL,
1355 0xFDFDFDFDFDFDFDFDULL,
1356 0xFDFDFDFDFDFDFDFDULL,
1357 0xFDFDFDFDFDFDFDFDULL,
1358 0xFDFDFDFDFDFDFDFDULL,
1359 0xFDFDFDFDFDFDFDFDULL
1360 }
1361 },
1362 {
1363 {
1364 0x0000000000000000ULL,
1365 0x0000000000000000ULL,
1366 0x0000000000000000ULL,
1367 0x0000000000000000ULL,
1368 0x0000000000000000ULL,
1369 0x0000000000000000ULL,
1370 0x0000000000000000ULL,
1371 0x0000000000000000ULL
1372 },
1373 {
1374 0x0000000000000000ULL,
1375 0x0000000000000000ULL,
1376 0x0000000000000000ULL,
1377 0x0000000000000000ULL,
1378 0x0000000000000000ULL,
1379 0x0000000000000000ULL,
1380 0x0000000000000000ULL,
1381 0x00000000000000FDULL
1382 },
1383 {
1384 0x0000000000000000ULL,
1385 0x0000000000000000ULL,
1386 0x0000000000000000ULL,
1387 0x0000000000000000ULL,
1388 0x0000000000000000ULL,
1389 0x0000000000000000ULL,
1390 0x00000000000000FDULL,
1391 0x000000000000FDFDULL
1392 },
1393 {
1394 0x0000000000000000ULL,
1395 0x0000000000000000ULL,
1396 0x0000000000000000ULL,
1397 0x0000000000000000ULL,
1398 0x0000000000000000ULL,
1399 0x00000000000000FDULL,
1400 0x000000000000FDFDULL,
1401 0x0000000000FDFDFDULL
1402 },
1403 {
1404 0x0000000000000000ULL,
1405 0x0000000000000000ULL,
1406 0x0000000000000000ULL,
1407 0x0000000000000000ULL,
1408 0x00000000000000FDULL,
1409 0x000000000000FDFDULL,
1410 0x0000000000FDFDFDULL,
1411 0x00000000FDFDFDFDULL
1412 },
1413 {
1414 0x0000000000000000ULL,
1415 0x0000000000000000ULL,
1416 0x0000000000000000ULL,
1417 0x00000000000000FDULL,
1418 0x000000000000FDFDULL,
1419 0x0000000000FDFDFDULL,
1420 0x00000000FDFDFDFDULL,
1421 0x000000FDFDFDFDFDULL
1422 },
1423 {
1424 0x0000000000000000ULL,
1425 0x0000000000000000ULL,
1426 0x00000000000000FDULL,
1427 0x000000000000FDFDULL,
1428 0x0000000000FDFDFDULL,
1429 0x00000000FDFDFDFDULL,
1430 0x000000FDFDFDFDFDULL,
1431 0x0000FDFDFDFDFDFDULL
1432 },
1433 {
1434 0x0000000000000000ULL,
1435 0x00000000000000FDULL,
1436 0x000000000000FDFDULL,
1437 0x0000000000FDFDFDULL,
1438 0x00000000FDFDFDFDULL,
1439 0x000000FDFDFDFDFDULL,
1440 0x0000FDFDFDFDFDFDULL,
1441 0x00FDFDFDFDFDFDFDULL
1442 },
1443 {
1444 0x00000000000000FDULL,
1445 0x000000000000FDFDULL,
1446 0x0000000000FDFDFDULL,
1447 0x00000000FDFDFDFDULL,
1448 0x000000FDFDFDFDFDULL,
1449 0x0000FDFDFDFDFDFDULL,
1450 0x00FDFDFDFDFDFDFDULL,
1451 0xFDFDFDFDFDFDFDFDULL
1452 },
1453 {
1454 0x000000000000FDFDULL,
1455 0x0000000000FDFDFDULL,
1456 0x00000000FDFDFDFDULL,
1457 0x000000FDFDFDFDFDULL,
1458 0x0000FDFDFDFDFDFDULL,
1459 0x00FDFDFDFDFDFDFDULL,
1460 0xFDFDFDFDFDFDFDFDULL,
1461 0xFDFDFDFDFDFDFDFDULL
1462 },
1463 {
1464 0x0000000000FDFDFDULL,
1465 0x00000000FDFDFDFDULL,
1466 0x000000FDFDFDFDFDULL,
1467 0x0000FDFDFDFDFDFDULL,
1468 0x00FDFDFDFDFDFDFDULL,
1469 0xFDFDFDFDFDFDFDFDULL,
1470 0xFDFDFDFDFDFDFDFDULL,
1471 0xFDFDFDFDFDFDFDFDULL
1472 },
1473 {
1474 0x00000000FDFDFDFDULL,
1475 0x000000FDFDFDFDFDULL,
1476 0x0000FDFDFDFDFDFDULL,
1477 0x00FDFDFDFDFDFDFDULL,
1478 0xFDFDFDFDFDFDFDFDULL,
1479 0xFDFDFDFDFDFDFDFDULL,
1480 0xFDFDFDFDFDFDFDFDULL,
1481 0xFDFDFDFDFDFDFDFDULL
1482 },
1483 {
1484 0x000000FDFDFDFDFDULL,
1485 0x0000FDFDFDFDFDFDULL,
1486 0x00FDFDFDFDFDFDFDULL,
1487 0xFDFDFDFDFDFDFDFDULL,
1488 0xFDFDFDFDFDFDFDFDULL,
1489 0xFDFDFDFDFDFDFDFDULL,
1490 0xFDFDFDFDFDFDFDFDULL,
1491 0xFDFDFDFDFDFDFDFDULL
1492 },
1493 {
1494 0x0000FDFDFDFDFDFDULL,
1495 0x00FDFDFDFDFDFDFDULL,
1496 0xFDFDFDFDFDFDFDFDULL,
1497 0xFDFDFDFDFDFDFDFDULL,
1498 0xFDFDFDFDFDFDFDFDULL,
1499 0xFDFDFDFDFDFDFDFDULL,
1500 0xFDFDFDFDFDFDFDFDULL,
1501 0xFDFDFDFDFDFDFDFDULL
1502 },
1503 {
1504 0x00FDFDFDFDFDFDFDULL,
1505 0xFDFDFDFDFDFDFDFDULL,
1506 0xFDFDFDFDFDFDFDFDULL,
1507 0xFDFDFDFDFDFDFDFDULL,
1508 0xFDFDFDFDFDFDFDFDULL,
1509 0xFDFDFDFDFDFDFDFDULL,
1510 0xFDFDFDFDFDFDFDFDULL,
1511 0xFDFDFDFDFDFDFDFDULL
1512 },
1513 {
1514 0xFDFDFDFDFDFDFDFDULL,
1515 0xFDFDFDFDFDFDFDFDULL,
1516 0xFDFDFDFDFDFDFDFDULL,
1517 0xFDFDFDFDFDFDFDFDULL,
1518 0xFDFDFDFDFDFDFDFDULL,
1519 0xFDFDFDFDFDFDFDFDULL,
1520 0xFDFDFDFDFDFDFDFDULL,
1521 0xFDFDFDFDFDFDFDFDULL
1522 }
1523 }
1524 };
1525
1526 static bool is_opening_screen;
1527 int32_t black_opening_count=0;
1528 int32_t black_opening_x,black_opening_y;
1529 int32_t black_opening_shape;
1530
1531 3281 int32_t choose_opening_shape()
1532 {
1533 // First, count how many bits are set
1534 3281 int32_t numBits=0;
1535 int32_t bitCounter;
1536
1537
2/2
✓ Branch 0 taken 16405 times.
✓ Branch 1 taken 3281 times.
19686 for(int32_t i=0; i<bosMAX; i++)
1538 {
1539
2/2
✓ Branch 0 taken 12908 times.
✓ Branch 1 taken 3497 times.
16405 if(COOLSCROLL&(1<<i))
1540 3497 numBits++;
1541 16405 }
1542
1543 // Shouldn't happen...
1544
1/2
✓ Branch 0 taken 3281 times.
✗ Branch 1 not taken.
3281 if(numBits==0)
1545 return bosCIRCLE;
1546
1547 // Pick a bit
1548 3281 bitCounter=zc_rand()%numBits+1;
1549
1550
2/2
✓ Branch 0 taken 4475 times.
✓ Branch 1 taken 26 times.
4501 for(int32_t i=0; i<bosMAX; i++)
1551 {
1552 // If this bit is set, decrement the bit counter
1553
2/2
✓ Branch 0 taken 1064 times.
✓ Branch 1 taken 3411 times.
4475 if(COOLSCROLL&(1<<i))
1554 3411 bitCounter--;
1555
1556 // When the counter hits 0, return a value based on
1557 // which bit it stopped on.
1558 // Reminder: enum {bosCIRCLE=0, bosOVAL, bosTRIANGLE, bosSMAS, bosFADEBLACK, bosMAX};
1559
2/2
✓ Branch 0 taken 3255 times.
✓ Branch 1 taken 1220 times.
4475 if(bitCounter==0)
1560 3255 return i;
1561 1220 }
1562
1563 // Shouldn't be necessary, but the compiler might complain, at least
1564 26 return bosCIRCLE;
1565 3281 }
1566
1567 739 void close_black_opening(int32_t x, int32_t y, bool wait, int32_t shape)
1568 {
1569 739 x -= viewport.x;
1570 739 y -= viewport.y;
1571
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 729 times.
739 black_opening_shape= (shape>-1 ? shape : choose_opening_shape());
1572
1573 739 int32_t w=framebuf->w, h=framebuf->h;
1574 739 int32_t blockrows=h/8, blockcolumns=32;
1575 739 int32_t xoffset=(x-(w/2))/8, yoffset=(y-(h/2))/8;
1576
1577
2/2
✓ Branch 0 taken 20692 times.
✓ Branch 1 taken 739 times.
21431 for(int32_t blockrow=0; blockrow<blockrows; ++blockrow) //30
1578 {
1579
2/2
✓ Branch 0 taken 662144 times.
✓ Branch 1 taken 20692 times.
682836 for(int32_t blockcolumn=0; blockcolumn<blockcolumns; ++blockcolumn) //40
1580 {
1581
2/2
✓ Branch 0 taken 273677 times.
✓ Branch 1 taken 388467 times.
662144 screen_triangles[blockrow][blockcolumn]=zc_max(abs(int32_t(double(blockcolumns-1)/2-blockcolumn+xoffset)),abs(int32_t(double(blockrows-1)/2-blockrow+yoffset)))|0x0100|((blockrow-yoffset<blockrows/2)?0:0x8000)|((blockcolumn-xoffset<blockcolumns/2)?0x4000:0);
1582 662144 }
1583 20692 }
1584
1585 739 black_opening_count = 66;
1586 739 black_opening_x = x;
1587 739 black_opening_y = y;
1588 739 lensclk = 0;
1589 //black_opening_shape=(black_opening_shape+1)%bosMAX;
1590
1591
1592
1/2
✓ Branch 0 taken 739 times.
✗ Branch 1 not taken.
739 if(black_opening_shape == bosFADEBLACK)
1593 {
1594 refreshTints();
1595 memcpy(tempblackpal, RAMpal, sizeof(RAMpal)); //Store palette in temp palette for fade effect
1596 }
1597
2/2
✓ Branch 0 taken 725 times.
✓ Branch 1 taken 14 times.
739 if(wait)
1598 {
1599 14 FFCore.warpScriptCheck();
1600
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 924 times.
938 for(int32_t i=0; i<66; i++)
1601 {
1602 924 draw_screen();
1603 924 advanceframe(true);
1604
1605
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 924 times.
924 if(Quit)
1606 {
1607 break;
1608 }
1609 924 }
1610 14 }
1611 739 }
1612
1613 2562 void open_black_opening(int32_t x, int32_t y, bool wait, int32_t shape)
1614 {
1615 2562 x -= viewport.x;
1616 2562 y -= viewport.y;
1617
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2552 times.
2562 black_opening_shape= (shape>-1 ? shape : choose_opening_shape());
1618
1619 2562 int32_t w=framebuf->w, h=framebuf->h;
1620 2562 int32_t blockrows=h/8, blockcolumns=32;
1621 2562 int32_t xoffset=(x-(w/2))/8, yoffset=(y-(h/2))/8;
1622
1623
2/2
✓ Branch 0 taken 71841 times.
✓ Branch 1 taken 2562 times.
74403 for(int32_t blockrow=0; blockrow<blockrows; ++blockrow) //30
1624 {
1625
2/2
✓ Branch 0 taken 2298912 times.
✓ Branch 1 taken 71841 times.
2370753 for(int32_t blockcolumn=0; blockcolumn<blockcolumns; ++blockcolumn) //40
1626 {
1627
2/2
✓ Branch 0 taken 1133172 times.
✓ Branch 1 taken 1165740 times.
2298912 screen_triangles[blockrow][blockcolumn]=zc_max(abs(int32_t(double(blockcolumns-1)/2-blockcolumn+xoffset)),abs(int32_t(double(blockrows-1)/2-blockrow+yoffset)))|0x0100|((blockrow-yoffset<blockrows/2)?0:0x8000)|((blockcolumn-xoffset<blockcolumns/2)?0x4000:0);
1628 2298912 }
1629 71841 }
1630
1631 2562 black_opening_count = -66;
1632 2562 black_opening_x = x;
1633 2562 black_opening_y = y;
1634 2562 lensclk = 0;
1635
1/2
✓ Branch 0 taken 2562 times.
✗ Branch 1 not taken.
2562 if(black_opening_shape == bosFADEBLACK)
1636 {
1637 refreshTints();
1638 memcpy(tempblackpal, RAMpal, sizeof(RAMpal)); //Store palette in temp palette for fade effect
1639 }
1640
2/2
✓ Branch 0 taken 368 times.
✓ Branch 1 taken 2194 times.
2562 if(wait)
1641 {
1642 2194 FFCore.warpScriptCheck();
1643
2/2
✓ Branch 0 taken 2193 times.
✓ Branch 1 taken 144815 times.
147008 for(int32_t i=0; i<66; i++)
1644 {
1645 144815 draw_screen();
1646 144815 advanceframe(true);
1647
1648
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 144814 times.
144815 if(Quit)
1649 {
1650 1 break;
1651 }
1652 144814 }
1653 2194 }
1654 2562 }
1655
1656 217098 void black_opening(BITMAP *dest,int32_t x,int32_t y,int32_t a,int32_t max_a)
1657 {
1658 217098 clear_to_color(tmp_scr,BLACK);
1659 217098 int32_t w=dest->w, h=dest->h;
1660
1661
4/6
✗ Branch 0 not taken.
✓ Branch 1 taken 9636 times.
✓ Branch 2 taken 1980 times.
✓ Branch 3 taken 20328 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 185154 times.
217098 switch(black_opening_shape)
1662 {
1663 case bosOVAL:
1664 {
1665 9636 double new_w=(w/2)+abs(w/2-x);
1666 9636 double new_h=(h/2)+abs(h/2-y);
1667 9636 double b=sqrt(((new_w*new_w)/4)+(new_h*new_h));
1668 9636 ellipsefill(tmp_scr,x,y,int32_t(2*a*b/max_a)/8*8,int32_t(a*b/max_a)/8*8,0);
1669 9636 break;
1670 }
1671
1672 case bosTRIANGLE:
1673 {
1674 1980 double new_w=(w/2)+abs(w/2-x);
1675 1980 double new_h=(h/2)+abs(h/2-y);
1676 1980 double r=a*(new_w*sqrt((double)3)+new_h)/max_a;
1677 1980 double P2= (PI/2);
1678 1980 double P23=(2*PI/3);
1679 1980 double P43=(4*PI/3);
1680 1980 double Pa= (-4*PI*a/(3*max_a));
1681 1980 double angle=P2+Pa;
1682 1980 double a0=angle;
1683 1980 double a2=angle+P23;
1684 1980 double a4=angle+P43;
1685 3960 triangle(tmp_scr, x+int32_t(zc::math::Cos(a0)*r), y-int32_t(zc::math::Sin(a0)*r),
1686 1980 x+int32_t(zc::math::Cos(a2)*r), y-int32_t(zc::math::Sin(a2)*r),
1687 1980 x+int32_t(zc::math::Cos(a4)*r), y-int32_t(zc::math::Sin(a4)*r),
1688 0);
1689 1980 break;
1690 }
1691
1692 case bosSMAS:
1693 {
1694
2/2
✓ Branch 0 taken 7260 times.
✓ Branch 1 taken 13068 times.
20328 int32_t distance=zc_max(abs(w/2-x),abs(h/2-y))/8;
1695
1696
2/2
✓ Branch 0 taken 569184 times.
✓ Branch 1 taken 20328 times.
589512 for(int32_t blockrow=0; blockrow<h/8; ++blockrow) //30
1697 {
1698
2/2
✓ Branch 0 taken 4553472 times.
✓ Branch 1 taken 569184 times.
5122656 for(int32_t linerow=0; linerow<8; ++linerow)
1699 {
1700 4553472 qword *triangleline=(qword*)(tmp_scr->line[(blockrow*8+linerow)]);
1701
1702
2/2
✓ Branch 0 taken 145711104 times.
✓ Branch 1 taken 4553472 times.
150264576 for(int32_t blockcolumn=0; blockcolumn<32; ++blockcolumn) //40
1703 {
1704 437133312 *triangleline=triangles[(screen_triangles[blockrow][blockcolumn]&0xC000)>>14]
1705
6/6
✓ Branch 0 taken 105268072 times.
✓ Branch 1 taken 40443032 times.
✓ Branch 2 taken 96140976 times.
✓ Branch 3 taken 49570128 times.
✓ Branch 4 taken 55697944 times.
✓ Branch 5 taken 40443032 times.
145711104 [zc_min(zc_max((((31+distance)*(max_a-a)/max_a)+((screen_triangles[blockrow][blockcolumn]&0x0FFF)-0x0100)-(15+distance)),0),15)]
1706 145711104 [linerow];
1707 145711104 ++triangleline;
1708 145711104 }
1709 4553472 }
1710 569184 }
1711
1712 20328 break;
1713 }
1714
1715 case bosFADEBLACK:
1716 {
1717 if(black_opening_count<0)
1718 {
1719 black_fade(zc_min(-black_opening_count,63));
1720 }
1721 else if(black_opening_count>0)
1722 {
1723 black_fade(63-zc_max(black_opening_count-3,0));
1724 }
1725 else black_fade(0);
1726 return; //no blitting from tmp_scr!
1727 }
1728
1729 185154 case bosCIRCLE:
1730 default:
1731 {
1732 185154 double new_w=(w/2)+abs(w/2-x);
1733 185154 double new_h=(h/2)+abs(h/2-y);
1734 185154 int32_t r=int32_t(sqrt((new_w*new_w)+(new_h*new_h))*a/max_a);
1735 //circlefill(tmp_scr,x,y,a<<3,0);
1736 185154 circlefill(tmp_scr,x,y,r,0);
1737 185154 break;
1738 }
1739 }
1740
1741 217098 masked_blit(tmp_scr,dest,0,0,0,0,320,240);
1742 217098 }
1743
1744 // fadeamnt is 0-63
1745 void black_fade(int32_t fadeamnt)
1746 {
1747 fadeamnt = _rgb_scale_6[fadeamnt];
1748 for(int32_t i=0; i < 0xEF; i++)
1749 {
1750 RAMpal[i].r = vbound(tempblackpal[i].r-fadeamnt,0,255);
1751 RAMpal[i].g = vbound(tempblackpal[i].g-fadeamnt,0,255);
1752 RAMpal[i].b = vbound(tempblackpal[i].b-fadeamnt,0,255);
1753 }
1754
1755 refreshpal = true;
1756 }
1757
1758 //----------------------------------------------------------------
1759
1760 201531218 bool item_disabled(int32_t item) //is this item disabled?
1761 {
1762
2/2
✓ Branch 0 taken 14503352 times.
✓ Branch 1 taken 187027866 times.
201531218 return (unsigned(item) < MAXITEMS && game->items_off[item] != 0);
1763 }
1764
1765 15650261 bool can_use_item(int32_t item_type, int32_t item) //can Hero use this item?
1766 {
1767
2/2
✓ Branch 0 taken 254624 times.
✓ Branch 1 taken 15395637 times.
15650261 if(current_item(item_type, true) >=item)
1768 {
1769 254624 return true;
1770 }
1771
1772 15395637 return false;
1773 15650261 }
1774
1775 43614908 bool has_item(int32_t item_type, int32_t it) //does Hero possess this item?
1776 {
1777
5/9
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 4421282 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 337472 times.
✓ Branch 6 taken 28761082 times.
✓ Branch 7 taken 9900006 times.
✓ Branch 8 taken 195066 times.
43614908 switch(item_type)
1778 {
1779 case itype_bomb:
1780 case itype_sbomb:
1781 {
1782 int32_t itemid = getItemID(itemsbuf, item_type, it);
1783
1784 if(itemid == -1)
1785 return false;
1786
1787 return (game->get_item(itemid));
1788 }
1789
1790 case itype_clock:
1791 {
1792 4421282 int32_t itemid = getItemID(itemsbuf, item_type, it);
1793
1794
2/4
✓ Branch 0 taken 4421282 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4421282 times.
✗ Branch 3 not taken.
4421282 if(itemid != -1 && (itemsbuf[itemid].flags & item_flag1)) //Active clock
1795 return (game->get_item(itemid));
1796 4421282 return Hero.getClock()?1:0;
1797 }
1798
1799 case itype_key:
1800 return (game->get_keys()>0);
1801
1802 case itype_magiccontainer:
1803 return (game->get_maxmagic()>=game->get_mp_per_block());
1804
1805 case itype_triforcepiece: //it: -2=any, -1=current level, other=that level
1806 {
1807
1/3
✓ Branch 0 taken 337472 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
337472 switch(it)
1808 {
1809 case -2:
1810 {
1811 for(int32_t i=0; i<MAXLEVELS; i++)
1812 {
1813 if(game->lvlitems[i]&liTRIFORCE)
1814 {
1815 return true;
1816 }
1817 }
1818
1819 return false;
1820 }
1821
1822 case -1:
1823 return (game->lvlitems[dlevel]&liTRIFORCE);
1824
1825 default:
1826
2/4
✓ Branch 0 taken 337472 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 337472 times.
337472 if(it>=0&&it<MAXLEVELS)
1827 {
1828 337472 return (game->lvlitems[it]&liTRIFORCE);
1829 }
1830
1831 break;
1832 }
1833
1834 return 0;
1835 }
1836
1837 case itype_map: //it: -2=any, -1=current level, other=that level
1838 {
1839
2/3
✓ Branch 0 taken 541626 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 28219456 times.
28761082 switch(it)
1840 {
1841 case -2:
1842 {
1843 for(int32_t i=0; i<MAXLEVELS; i++)
1844 {
1845 if(game->lvlitems[i]&liMAP)
1846 {
1847 return true;
1848 }
1849 }
1850
1851 return false;
1852 }
1853
1854 case -1:
1855 28219456 return (game->lvlitems[dlevel]&liMAP)!=0;
1856
1857 default:
1858
2/4
✓ Branch 0 taken 541626 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 541626 times.
541626 if(it>=0&&it<MAXLEVELS)
1859 {
1860 541626 return (game->lvlitems[it]&liMAP)!=0;
1861 }
1862
1863 break;
1864 }
1865
1866 return 0;
1867 }
1868
1869 case itype_compass: //it: -2=any, -1=current level, other=that level
1870 {
1871
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 9900006 times.
9900006 switch(it)
1872 {
1873 case -2:
1874 {
1875 for(int32_t i=0; i<MAXLEVELS; i++)
1876 {
1877 if(game->lvlitems[i]&liCOMPASS)
1878 {
1879 return true;
1880 }
1881 }
1882
1883 return false;
1884 }
1885
1886 case -1:
1887 9900006 return (game->lvlitems[dlevel]&liCOMPASS)!=0;
1888
1889 default:
1890 if(it>=0&&it<MAXLEVELS)
1891 {
1892 return (game->lvlitems[it]&liCOMPASS)!=0;
1893 }
1894
1895 break;
1896 }
1897 return 0;
1898 }
1899
1900 case itype_bosskey: //it: -2=any, -1=current level, other=that level
1901 {
1902
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 195066 times.
195066 switch(it)
1903 {
1904 case -2:
1905 {
1906 for(int32_t i=0; i<MAXLEVELS; i++)
1907 {
1908 if(game->lvlitems[i]&liBOSSKEY)
1909 {
1910 return true;
1911 }
1912 }
1913
1914 return false;
1915 }
1916
1917 case -1:
1918 195066 return (game->lvlitems[dlevel]&liBOSSKEY)?1:0;
1919
1920 default:
1921 if(it>=0&&it<MAXLEVELS)
1922 {
1923 return (game->lvlitems[it]&liBOSSKEY)?1:0;
1924 }
1925 break;
1926 }
1927 return 0;
1928 }
1929
1930 default:
1931 int32_t itemid = getItemID(itemsbuf, item_type, it);
1932
1933 if(itemid == -1)
1934 return false;
1935
1936 return game->get_item(itemid);
1937 }
1938 43614908 }
1939
1940 151022287 int current_item(int item_type, bool checkmagic, bool jinx_check, bool check_bunny)
1941 {
1942
9/9
✓ Branch 0 taken 4421282 times.
✓ Branch 1 taken 115652031 times.
✓ Branch 2 taken 4421282 times.
✓ Branch 3 taken 4421282 times.
✓ Branch 4 taken 4421282 times.
✓ Branch 5 taken 4421282 times.
✓ Branch 6 taken 4421282 times.
✓ Branch 7 taken 4421282 times.
✓ Branch 8 taken 4421282 times.
151022287 switch(item_type)
1943 {
1944 case itype_clock:
1945 {
1946 4421282 int maxid = current_item_id(item_type, checkmagic, jinx_check, check_bunny);
1947
1948
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4421282 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4421282 if(maxid != -1 && (itemsbuf[maxid].flags & item_flag1)) //Active clock
1949 return itemsbuf[maxid].fam_type;
1950
1951 4421282 return has_item(itype_clock,1) ? 1 : 0;
1952 }
1953
1954 case itype_key:
1955 4421282 return game->get_keys();
1956
1957 case itype_lkey:
1958 4421282 return game->lvlkeys[get_dlevel()];
1959
1960 case itype_magiccontainer:
1961 4421282 return game->get_maxmagic()/game->get_mp_per_block();
1962
1963 case itype_triforcepiece:
1964 {
1965 4421282 int count=0;
1966
1967
2/2
✓ Branch 0 taken 2263696384 times.
✓ Branch 1 taken 4421282 times.
2268117666 for(int i=0; i<MAXLEVELS; i++)
1968 {
1969 2263696384 count+=(game->lvlitems[i]&liTRIFORCE)?1:0;
1970 2263696384 }
1971
1972 4421282 return count;
1973 }
1974
1975 case itype_map:
1976 {
1977 4421282 int count=0;
1978
1979
2/2
✓ Branch 0 taken 2263696384 times.
✓ Branch 1 taken 4421282 times.
2268117666 for(int i=0; i<MAXLEVELS; i++)
1980 {
1981 2263696384 count+=(game->lvlitems[i]&liMAP)?1:0;
1982 2263696384 }
1983
1984 4421282 return count;
1985 }
1986
1987 case itype_compass:
1988 {
1989 4421282 int count=0;
1990
1991
2/2
✓ Branch 0 taken 2263696384 times.
✓ Branch 1 taken 4421282 times.
2268117666 for(int i=0; i<MAXLEVELS; i++)
1992 {
1993 2263696384 count+=(game->lvlitems[i]&liCOMPASS)?1:0;
1994 2263696384 }
1995
1996 4421282 return count;
1997 }
1998
1999 case itype_bosskey:
2000 {
2001 4421282 int count=0;
2002
2003
2/2
✓ Branch 0 taken 2263696384 times.
✓ Branch 1 taken 4421282 times.
2268117666 for(int i=0; i<MAXLEVELS; i++)
2004 {
2005 2263696384 count+=(game->lvlitems[i]&liBOSSKEY)?1:0;
2006 2263696384 }
2007
2008 4421282 return count;
2009 }
2010
2011 default:
2012 115652031 int maxid = current_item_id(item_type, checkmagic, jinx_check, check_bunny);
2013
2014
2/2
✓ Branch 0 taken 81961102 times.
✓ Branch 1 taken 33690929 times.
115652031 if(maxid == -1)
2015 81961102 return 0;
2016
2017 33690929 return itemsbuf[maxid].fam_type;
2018 }
2019 151022287 }
2020
2021 409 std::map<int32_t, int32_t> itemcache;
2022 409 std::map<int32_t, int32_t> itemcache_cost;
2023
2024 void removeFromItemCache(int32_t itemclass)
2025 {
2026 itemcache.erase(itemclass);
2027 itemcache_cost.erase(itemclass);
2028 cache_tile_mod_clear();
2029 }
2030
2031 13058872 void flushItemCache(bool justcost)
2032 {
2033 13058872 itemcache_cost.clear();
2034
2/2
✓ Branch 0 taken 12985194 times.
✓ Branch 1 taken 73678 times.
13058872 if(!justcost)
2035 73678 itemcache.clear();
2036
2/2
✓ Branch 0 taken 6357672 times.
✓ Branch 1 taken 6627522 times.
12985194 else if(replay_version_check(0,19))
2037 6357672 return;
2038
2039 6701200 cache_tile_mod_clear();
2040
2041 //also fix the active subscreen if items were deleted -DD
2042
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6701200 times.
6701200 if(game != NULL)
2043 {
2044 6701200 verifyBothWeapons();
2045 6701200 refresh_subscr_items();
2046 6701200 }
2047 13058872 }
2048
2049 // This is used often, so it should be as direct as possible.
2050 3025533722 int _c_item_id_internal(int itemtype, bool checkmagic, bool jinx_check, bool check_bunny)
2051 {
2052 3025533722 bool use_cost_cache = replay_version_check(19);
2053
2/2
✓ Branch 0 taken 2885961713 times.
✓ Branch 1 taken 139572009 times.
3025533722 if(jinx_check)
2054 {
2055 //special case for shields...
2056
3/4
✓ Branch 0 taken 54400618 times.
✓ Branch 1 taken 85171391 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 54400618 times.
139572009 if (itemtype == itype_shield && !HeroShieldClk())
2057 54400618 jinx_check = false;
2058
4/4
✓ Branch 0 taken 52524626 times.
✓ Branch 1 taken 32646765 times.
✓ Branch 2 taken 10856084 times.
✓ Branch 3 taken 41668542 times.
85171391 else if(!(HeroSwordClk() || HeroItemClk()))
2059 41668542 jinx_check = false; //not jinxed
2060 139572009 }
2061
4/4
✓ Branch 0 taken 119620 times.
✓ Branch 1 taken 3025414102 times.
✓ Branch 2 taken 1853 times.
✓ Branch 3 taken 117767 times.
3025533722 if(!Hero.BunnyClock() || itemtype == itype_pearl) // bunny_check does not apply
2062 3025415955 check_bunny = false;
2063
2/2
✓ Branch 0 taken 2967763224 times.
✓ Branch 1 taken 57770498 times.
3025533722 if(itemtype == itype_ring) checkmagic = true;
2064
4/4
✓ Branch 0 taken 2982030873 times.
✓ Branch 1 taken 43502849 times.
✓ Branch 2 taken 297306347 times.
✓ Branch 3 taken 25153195 times.
3347993264 if (!jinx_check && !check_bunny
2065
4/4
✓ Branch 0 taken 2981940714 times.
✓ Branch 1 taken 90159 times.
✓ Branch 2 taken 322459542 times.
✓ Branch 3 taken 2659481172 times.
2982030873 && (use_cost_cache || itemtype != itype_ring))
2066 {
2067
4/4
✓ Branch 0 taken 563293094 times.
✓ Branch 1 taken 2393494425 times.
✓ Branch 2 taken 246782821 times.
✓ Branch 3 taken 316510273 times.
2956787519 auto& cache = checkmagic && use_cost_cache ? itemcache_cost : itemcache;
2068 2956787519 auto res = cache.find(itemtype);
2069
2070
2/2
✓ Branch 0 taken 2811201870 times.
✓ Branch 1 taken 145585649 times.
2956787519 if(res != cache.end())
2071 2811201870 return res->second;
2072 145585649 }
2073
2074 214331852 int result = -1;
2075 214331852 int highestlevel = -1;
2076
2077
2/2
✓ Branch 0 taken 54868954112 times.
✓ Branch 1 taken 214331852 times.
55083285964 for(int i=0; i<MAXITEMS; i++)
2078 {
2079
6/6
✓ Branch 0 taken 6000678208 times.
✓ Branch 1 taken 48868275904 times.
✓ Branch 2 taken 96486925 times.
✓ Branch 3 taken 5904191283 times.
✓ Branch 4 taken 82048 times.
✓ Branch 5 taken 96404877 times.
54868954112 if(game->get_item(i) && itemsbuf[i].family==itemtype && !item_disabled(i))
2080 {
2081
4/4
✓ Branch 0 taken 91730936 times.
✓ Branch 1 taken 4673941 times.
✓ Branch 2 taken 2473305 times.
✓ Branch 3 taken 89257631 times.
96404877 if(checkmagic && itemtype != itype_magicring)
2082
2/2
✓ Branch 0 taken 89256930 times.
✓ Branch 1 taken 701 times.
89257631 if(!checkmagiccost(i))
2083 701 continue;
2084
6/6
✓ Branch 0 taken 88807787 times.
✓ Branch 1 taken 7596389 times.
✓ Branch 2 taken 1253652 times.
✓ Branch 3 taken 6342737 times.
✓ Branch 4 taken 4146834 times.
✓ Branch 5 taken 3449555 times.
96404176 if(jinx_check && (usesSwordJinx(i) ? HeroSwordClk() : HeroItemClk()))
2085
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3449555 times.
3449555 if(!(itemsbuf[i].flags & item_jinx_immune))
2086 3449555 continue;
2087
3/4
✓ Branch 0 taken 100571 times.
✓ Branch 1 taken 92854050 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 100571 times.
92954621 if(check_bunny && !checkbunny(i))
2088 100571 continue;
2089
2090
2/2
✓ Branch 0 taken 8438933 times.
✓ Branch 1 taken 84415117 times.
92854050 if(itemsbuf[i].fam_type >= highestlevel)
2091 {
2092 84415117 highestlevel = itemsbuf[i].fam_type;
2093 84415117 result=i;
2094 84415117 }
2095 92854050 }
2096 54865403285 }
2097
2098
4/4
✓ Branch 0 taken 170829003 times.
✓ Branch 1 taken 43502849 times.
✓ Branch 2 taken 90159 times.
✓ Branch 3 taken 170738844 times.
214331852 if(!(jinx_check || check_bunny)) //Can't cache jinx_check/check_bunny
2099 {
2100
2/2
✓ Branch 0 taken 128940653 times.
✓ Branch 1 taken 41798191 times.
170738844 if (use_cost_cache)
2101 {
2102
2/2
✓ Branch 0 taken 113026780 times.
✓ Branch 1 taken 15913873 times.
128940653 if (!checkmagic)
2103 15913873 itemcache[itemtype] = result;
2104
6/6
✓ Branch 0 taken 15913873 times.
✓ Branch 1 taken 113026780 times.
✓ Branch 2 taken 688536 times.
✓ Branch 3 taken 15225337 times.
✓ Branch 4 taken 673573 times.
✓ Branch 5 taken 14963 times.
128940653 if (checkmagic || result < 0 || checkmagiccost(result))
2105 128925690 itemcache_cost[itemtype] = result;
2106 128940653 }
2107 else
2108 {
2109 41798191 itemcache[itemtype] = result;
2110 }
2111 170738844 }
2112 214331852 return result;
2113 3025533722 }
2114
2115 // 'jinx_check' indicates that the highest level item *immune to jinxes* should be returned.
2116 2982532997 int current_item_id(int itype, bool checkmagic, bool jinx_check, bool check_bunny)
2117 {
2118
2/4
✓ Branch 0 taken 2982532997 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2982532997 times.
2982532997 if(itype < 0 || itype >= itype_max) return -1;
2119
1/2
✓ Branch 0 taken 2982532997 times.
✗ Branch 1 not taken.
2982532997 if(game->OverrideItems[itype] > -2)
2120 {
2121 auto ovid = game->OverrideItems[itype];
2122 if(ovid < 0 || ovid >= MAXITEMS)
2123 return -1;
2124 if(itemsbuf[ovid].family == itype)
2125 {
2126 if(itype == itype_magicring)
2127 checkmagic = false;
2128 else if(itype == itype_ring)
2129 checkmagic = true;
2130
2131 if(checkmagic && !checkmagiccost(ovid))
2132 return -1;
2133
2134 if (jinx_check && !checkitem_jinx(ovid))
2135 {
2136 return -1;
2137 }
2138 return ovid;
2139 }
2140 }
2141 2982532997 auto ret = _c_item_id_internal(itype,checkmagic,jinx_check,check_bunny);
2142
2/2
✓ Branch 0 taken 96571284 times.
✓ Branch 1 taken 2885961713 times.
2982532997 if(!jinx_check) //If not already a jinx-immune-only check...
2143 {
2144 //And the player IS jinxed...
2145
2/2
✓ Branch 0 taken 2842960988 times.
✓ Branch 1 taken 43000725 times.
2885961713 if(HeroIsJinxed())
2146 {
2147 //Then do a jinx-immune-only check here
2148 43000725 auto ret2 = _c_item_id_internal(itype,checkmagic,true,check_bunny);
2149 //And *IF IT FINDS A VALID ITEM*, return that one instead! -Em
2150 //Should NOT need a compat rule, as this should always return -1 in old quests.
2151
2/2
✓ Branch 0 taken 3265892 times.
✓ Branch 1 taken 39734833 times.
43000725 if(ret2 > -1) return ret2;
2152 39734833 }
2153 2882695821 }
2154 2979267105 return ret;
2155 2982532997 }
2156
2157 66328973 int current_item_power(int itemtype, bool checkmagic, bool jinx_check, bool check_bunny)
2158 {
2159 66328973 int result = current_item_id(itemtype, checkmagic, jinx_check, check_bunny);
2160
2/2
✓ Branch 0 taken 35521595 times.
✓ Branch 1 taken 30807378 times.
66328973 return (result<0) ? 0 : itemsbuf[result].power;
2161 }
2162
2163 26 int32_t heart_container_id()
2164 {
2165
1/2
✓ Branch 0 taken 754 times.
✗ Branch 1 not taken.
754 for(int32_t i=0; i<MAXITEMS; i++)
2166 {
2167
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 728 times.
754 if(itemsbuf[i].family == itype_heartcontainer)
2168 {
2169 26 return i;
2170 }
2171 728 }
2172 return -1;
2173 26 }
2174
2175 struct tilemod_cache_state_t
2176 {
2177
6/6
✓ Branch 0 taken 4420926 times.
✓ Branch 1 taken 8544959 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8544957 times.
✓ Branch 4 taken 354 times.
✓ Branch 5 taken 8544603 times.
21510844 bool operator==(const tilemod_cache_state_t&) const = default;
2178
2179 bool valid;
2180 bool bunny_clock;
2181 bool superman;
2182 int shield;
2183 };
2184 tilemod_cache_state_t tilemod_cache_state;
2185 int32_t tilemod_cache_value;
2186
2187 6702745 void cache_tile_mod_clear()
2188 {
2189 6702745 tilemod_cache_state = {false};
2190 6702745 }
2191
2192 12965885 int32_t item_tile_mod()
2193 {
2194 51863540 tilemod_cache_state_t state = {
2195 .valid = true,
2196 12965885 .bunny_clock = Hero.BunnyClock() != 0,
2197 12965885 .superman = Hero.superman,
2198 12965885 .shield = Hero.active_shield_id,
2199 };
2200
2/2
✓ Branch 0 taken 8544603 times.
✓ Branch 1 taken 4421282 times.
12965885 if (tilemod_cache_state == state)
2201 8544603 return tilemod_cache_value;
2202
2203 4421282 int32_t tile=0;
2204 4421282 bool check_bombcost = !get_qr(qr_BROKEN_BOMB_AMMO_COSTS);
2205
4/4
✓ Branch 0 taken 4007985 times.
✓ Branch 1 taken 413297 times.
✓ Branch 2 taken 3079190 times.
✓ Branch 3 taken 928795 times.
4421282 if(check_bombcost || game->get_bombs())
2206 {
2207 3492487 int32_t itemid = current_item_id(itype_bomb,check_bombcost);
2208
3/4
✓ Branch 0 taken 3432967 times.
✓ Branch 1 taken 59520 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3432967 times.
3492487 if(itemid > -1 && checkbunny(itemid))
2209 3432967 tile+=itemsbuf[itemid].ltm;
2210 3492487 }
2211
2212
4/4
✓ Branch 0 taken 4007985 times.
✓ Branch 1 taken 413297 times.
✓ Branch 2 taken 965298 times.
✓ Branch 3 taken 3042687 times.
4421282 if(check_bombcost || game->get_sbombs())
2213 {
2214 1378595 int32_t itemid = current_item_id(itype_sbomb,check_bombcost);
2215
3/4
✓ Branch 0 taken 965057 times.
✓ Branch 1 taken 413538 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 965057 times.
1378595 if(itemid > -1 && checkbunny(itemid))
2216 965057 tile+=itemsbuf[itemid].ltm;
2217 1378595 }
2218
2219
2/2
✓ Branch 0 taken 4408546 times.
✓ Branch 1 taken 12736 times.
4421282 if(current_item(itype_clock))
2220 {
2221 12736 int32_t itemid =
2222
2/2
✓ Branch 0 taken 12704 times.
✓ Branch 1 taken 32 times.
12736 get_qr(qr_HARDCODED_LITEM_LTMS)
2223 ? iClock
2224 32 : getHighestLevelEvenUnowned(itemsbuf, itype_clock);
2225
2/4
✓ Branch 0 taken 12736 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12736 times.
12736 if(itemid > -1 && checkbunny(itemid))
2226 12736 tile+=itemsbuf[itemid].ltm;
2227 12736 }
2228
2229
2/2
✓ Branch 0 taken 3775640 times.
✓ Branch 1 taken 645642 times.
4421282 if(current_item(itype_key))
2230 {
2231 645642 int32_t itemid =
2232
2/2
✓ Branch 0 taken 608640 times.
✓ Branch 1 taken 37002 times.
645642 get_qr(qr_HARDCODED_LITEM_LTMS)
2233 ? iKey
2234 37002 : getHighestLevelEvenUnowned(itemsbuf, itype_key);
2235
2/4
✓ Branch 0 taken 645642 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 645642 times.
645642 if(itemid > -1 && checkbunny(itemid))
2236 645642 tile+=itemsbuf[itemid].ltm;
2237 645642 }
2238
2239
2/2
✓ Branch 0 taken 3920397 times.
✓ Branch 1 taken 500885 times.
4421282 if(current_item(itype_lkey))
2240 {
2241 500885 int32_t itemid =
2242
2/2
✓ Branch 0 taken 414169 times.
✓ Branch 1 taken 86716 times.
500885 get_qr(qr_HARDCODED_LITEM_LTMS)
2243 ? iLevelKey
2244 86716 : getHighestLevelEvenUnowned(itemsbuf, itype_lkey);
2245
2/4
✓ Branch 0 taken 500885 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 500885 times.
500885 if(itemid > -1 && checkbunny(itemid))
2246 500885 tile+=itemsbuf[itemid].ltm;
2247 500885 }
2248
2249
2/2
✓ Branch 0 taken 1586452 times.
✓ Branch 1 taken 2834830 times.
4421282 if(current_item(itype_map))
2250 {
2251 2834830 int32_t itemid =
2252
2/2
✓ Branch 0 taken 2823834 times.
✓ Branch 1 taken 10996 times.
2834830 get_qr(qr_HARDCODED_LITEM_LTMS)
2253 ? iMap
2254 10996 : getHighestLevelEvenUnowned(itemsbuf, itype_map);
2255
2/4
✓ Branch 0 taken 2834830 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2834830 times.
2834830 if(itemid > -1 && checkbunny(itemid))
2256 2834830 tile+=itemsbuf[itemid].ltm;
2257 2834830 }
2258
2259
2/2
✓ Branch 0 taken 2109293 times.
✓ Branch 1 taken 2311989 times.
4421282 if(current_item(itype_compass))
2260 {
2261 2311989 int32_t itemid =
2262
2/2
✓ Branch 0 taken 2295941 times.
✓ Branch 1 taken 16048 times.
2311989 get_qr(qr_HARDCODED_LITEM_LTMS)
2263 ? iCompass
2264 16048 : getHighestLevelEvenUnowned(itemsbuf, itype_compass);
2265
2/4
✓ Branch 0 taken 2311989 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2311989 times.
2311989 if(itemid > -1 && checkbunny(itemid))
2266 2311989 tile+=itemsbuf[itemid].ltm;
2267 2311989 }
2268
2269
2/2
✓ Branch 0 taken 1334866 times.
✓ Branch 1 taken 3086416 times.
4421282 if(current_item(itype_bosskey))
2270 {
2271 3086416 int32_t itemid =
2272
2/2
✓ Branch 0 taken 2993139 times.
✓ Branch 1 taken 93277 times.
3086416 get_qr(qr_HARDCODED_LITEM_LTMS)
2273 ? iBossKey
2274 93277 : getHighestLevelEvenUnowned(itemsbuf, itype_bosskey);
2275
2/4
✓ Branch 0 taken 3086416 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3086416 times.
3086416 if(itemid > -1 && checkbunny(itemid))
2276 3086416 tile+=itemsbuf[itemid].ltm;
2277 3086416 }
2278
2279
2/2
✓ Branch 0 taken 48285 times.
✓ Branch 1 taken 4372997 times.
4421282 if(current_item(itype_magiccontainer))
2280 {
2281 4372997 int32_t itemid =
2282
2/2
✓ Branch 0 taken 3904340 times.
✓ Branch 1 taken 468657 times.
4372997 get_qr(qr_HARDCODED_LITEM_LTMS)
2283 ? iMagicC
2284 468657 : getHighestLevelEvenUnowned(itemsbuf, itype_magiccontainer);
2285
3/4
✓ Branch 0 taken 4372997 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 4372980 times.
4372997 if(itemid > -1 && checkbunny(itemid))
2286 4372980 tile+=itemsbuf[itemid].ltm;
2287 4372997 }
2288
2289
2/2
✓ Branch 0 taken 1314802 times.
✓ Branch 1 taken 3106480 times.
4421282 if(current_item(itype_triforcepiece))
2290 {
2291 3106480 int32_t itemid =
2292
2/2
✓ Branch 0 taken 3069478 times.
✓ Branch 1 taken 37002 times.
3106480 get_qr(qr_HARDCODED_LITEM_LTMS)
2293 ? iTriforce
2294 37002 : getHighestLevelEvenUnowned(itemsbuf, itype_triforcepiece);
2295
2/4
✓ Branch 0 taken 3106480 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3106480 times.
3106480 if(itemid > -1 && checkbunny(itemid))
2296 3106480 tile+=itemsbuf[itemid].ltm;
2297 3106480 }
2298
2299
2/2
✓ Branch 0 taken 2263696384 times.
✓ Branch 1 taken 4421282 times.
2268117666 for(int32_t i=0; i<itype_max; i++)
2300 {
2301
2/2
✓ Branch 0 taken 2023628800 times.
✓ Branch 1 taken 240067584 times.
2263696384 if(!get_qr(qr_HARDCODED_LITEM_LTMS))
2302 {
2303
2/2
✓ Branch 0 taken 4688820 times.
✓ Branch 1 taken 235378764 times.
240067584 switch(i)
2304 {
2305 case itype_bomb:
2306 case itype_sbomb:
2307 case itype_clock:
2308 case itype_key:
2309 case itype_lkey:
2310 case itype_map:
2311 case itype_compass:
2312 case itype_bosskey:
2313 case itype_magiccontainer:
2314 case itype_triforcepiece:
2315 4688820 continue; //already handled
2316 }
2317 235378764 }
2318 2259007564 int32_t itemid = current_item_id(i,false);
2319
2/2
✓ Branch 0 taken 2254586282 times.
✓ Branch 1 taken 4421282 times.
2259007564 if(i == itype_shield)
2320 4421282 itemid = getCurrentShield(false);
2321
2322
4/4
✓ Branch 0 taken 115677551 times.
✓ Branch 1 taken 2143330013 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 115677550 times.
2259007564 if(itemid < 0 || !checkbunny(itemid))
2323 2143330014 continue;
2324
2325 115677550 itemdata const& itm = itemsbuf[itemid];
2326
2327
2/2
✓ Branch 0 taken 111976856 times.
✓ Branch 1 taken 3700694 times.
115677550 switch(itm.family)
2328 {
2329 case itype_shield:
2330
1/2
✓ Branch 0 taken 3700694 times.
✗ Branch 1 not taken.
3700694 if(itm.flags & item_flag9) //active shield
2331 {
2332 if(!usingActiveShield(itemid))
2333 {
2334 tile+=itm.misc6; //'Inactive PTM'
2335 continue;
2336 }
2337 }
2338 3700694 break;
2339 }
2340
2341 115677550 tile+=itm.ltm;
2342 115677550 }
2343
2344 4421282 tilemod_cache_value = tile;
2345 4421282 tilemod_cache_state = state;
2346 4421282 return tile;
2347 12965885 }
2348
2349 12965885 int32_t bunny_tile_mod()
2350 {
2351
2/2
✓ Branch 0 taken 1870 times.
✓ Branch 1 taken 12964015 times.
12965885 if(Hero.BunnyClock())
2352 {
2353 1870 return game->get_bunny_ltm();
2354 }
2355 12964015 return 0;
2356 12965885 }
2357
2358 // Hints are drawn on a separate layer to combo reveals.
2359 // TODO: move out of zc_sys.cpp, weird place for this code.
2360 20058 void draw_lens_under(BITMAP *dest, bool layer)
2361 {
2362 //Lens flag 1: Replacement for qr_LENSHINTS; if set, lens will show hints. Does nothing if flag 2 is set.
2363 //Lens flag 2: Disable "hints", prevent rendering of Secret Combos
2364 //Lens flag 3: Don't show armos/chest/dive items
2365 //Lens flag 4: Show Raft Paths
2366 //Lens flag 5: Show Invisible Enemies
2367
4/4
✓ Branch 0 taken 19602 times.
✓ Branch 1 taken 456 times.
✓ Branch 2 taken 9801 times.
✓ Branch 3 taken 9801 times.
20058 bool hints = (itemsbuf[Hero.getLastLensID()].flags & item_flag2) ? false : (layer && (itemsbuf[Hero.getLastLensID()].flags & item_flag1));
2368
2369 20058 int32_t strike_hint_table[11]=
2370 {
2371 mfARROW, mfBOMB, mfBRANG, mfWANDMAGIC,
2372 mfSWORD, mfREFMAGIC, mfHOOKSHOT,
2373 mfREFFIREBALL, mfHAMMER, mfSWORDBEAM, mfWAND
2374 };
2375
2376 {
2377 20058 int32_t blink_rate=flash_reduction_enabled()?6:1;
2378 20058 int32_t tempitem, tempweapon=0;
2379 20058 strike_hint=strike_hint_table[strike_hint_counter];
2380
2381
2/2
✓ Branch 0 taken 19459 times.
✓ Branch 1 taken 599 times.
20058 if(strike_hint_timer>32)
2382 {
2383 599 strike_hint_timer=0;
2384 599 strike_hint_counter=((strike_hint_counter+1)%11);
2385 599 }
2386
2387 20058 ++strike_hint_timer;
2388
2389 3550266 for_every_visible_rpos_layer0([&](const rpos_handle_t& rpos_handle) {
2390 3530208 mapscr* scr = rpos_handle.scr;
2391 7306676 auto [x, y] = rpos_handle.xy();
2392 7060416 y += playing_field_offset;
2393
2394 3530208 int32_t tempitemx=-16, tempitemy=-16;
2395 3530208 int32_t tempweaponx=-16, tempweapony=-16;
2396
2397
2/2
✓ Branch 0 taken 7060416 times.
✓ Branch 1 taken 3530208 times.
10590624 for(int32_t iter=0; iter<2; ++iter)
2398 {
2399 7060416 int32_t checkflag=0;
2400
2401
2/2
✓ Branch 0 taken 3530208 times.
✓ Branch 1 taken 3530208 times.
7060416 if(iter==0)
2402 {
2403 3530208 checkflag = rpos_handle.cflag();
2404 3530208 }
2405 else
2406 {
2407 3530208 checkflag = rpos_handle.sflag();
2408 }
2409
2410
2/2
✓ Branch 0 taken 7059318 times.
✓ Branch 1 taken 1098 times.
7060416 if(checkflag==mfSTRIKE)
2411 {
2412
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 906 times.
1098 if(!hints)
2413 {
2414
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSTRIKE],scr->secretcset[sSTRIKE]);
2415 906 }
2416 else
2417 {
2418 192 checkflag = strike_hint;
2419 }
2420 1098 }
2421
2422
21/36
✓ Branch 0 taken 6911766 times.
✓ Branch 1 taken 3258 times.
✓ Branch 2 taken 108898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2602 times.
✓ Branch 5 taken 28750 times.
✓ Branch 6 taken 2418 times.
✓ Branch 7 taken 504 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 814 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 93 times.
✓ Branch 15 taken 96 times.
✓ Branch 16 taken 24 times.
✓ Branch 17 taken 25 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 138 times.
✓ Branch 21 taken 16 times.
✓ Branch 22 taken 16 times.
✓ Branch 23 taken 7 times.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 16 times.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✓ Branch 31 taken 17 times.
✓ Branch 32 taken 35 times.
✓ Branch 33 taken 17 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 906 times.
7060416 switch(checkflag)
2423 {
2424 case 0:
2425 case mfZELDA:
2426 case mfPUSHED:
2427 case mfENEMY0:
2428 case mfENEMY1:
2429 case mfENEMY2:
2430 case mfENEMY3:
2431 case mfENEMY4:
2432 case mfENEMY5:
2433 case mfENEMY6:
2434 case mfENEMY7:
2435 case mfENEMY8:
2436 case mfENEMY9:
2437 case mfSINGLE:
2438 case mfSINGLE16:
2439 case mfNOENEMY:
2440 case mfTRAP_H:
2441 case mfTRAP_V:
2442 case mfTRAP_4:
2443 case mfTRAP_LR:
2444 case mfTRAP_UD:
2445 case mfNOGROUNDENEMY:
2446 case mfNOBLOCKS:
2447 case mfSCRIPT1:
2448 case mfSCRIPT2:
2449 case mfSCRIPT3:
2450 case mfSCRIPT4:
2451 case mfSCRIPT5:
2452 case mfSCRIPT6:
2453 case mfSCRIPT7:
2454 case mfSCRIPT8:
2455 case mfSCRIPT9:
2456 case mfSCRIPT10:
2457 case mfSCRIPT11:
2458 case mfSCRIPT12:
2459 case mfSCRIPT13:
2460 case mfSCRIPT14:
2461 case mfSCRIPT15:
2462 case mfSCRIPT16:
2463 case mfSCRIPT17:
2464 case mfSCRIPT18:
2465 case mfSCRIPT19:
2466 case mfSCRIPT20:
2467 case mfPITHOLE:
2468 case mfPITFALLFLOOR:
2469 case mfLAVA:
2470 case mfICE:
2471 case mfICEDAMAGE:
2472 case mfDAMAGE1:
2473 case mfDAMAGE2:
2474 case mfDAMAGE4:
2475 case mfDAMAGE8:
2476 case mfDAMAGE16:
2477 case mfDAMAGE32:
2478 case mfFREEZEALL:
2479 case mfFREZEALLANSFFCS:
2480 case mfFREEZEFFCSOLY:
2481 case mfSCRITPTW1TRIG:
2482 case mfSCRITPTW2TRIG:
2483 case mfSCRITPTW3TRIG:
2484 case mfSCRITPTW4TRIG:
2485 case mfSCRITPTW5TRIG:
2486 case mfSCRITPTW6TRIG:
2487 case mfSCRITPTW7TRIG:
2488 case mfSCRITPTW8TRIG:
2489 case mfSCRITPTW9TRIG:
2490 case mfSCRITPTW10TRIG:
2491 case mfTROWEL:
2492 case mfTROWELNEXT:
2493 case mfTROWELSPECIALITEM:
2494 case mfSLASHPOT:
2495 case mfLIFTPOT:
2496 case mfLIFTORSLASH:
2497 case mfLIFTROCK:
2498 case mfLIFTROCKHEAVY:
2499 case mfDROPITEM:
2500 case mfSPECIALITEM:
2501 case mfDROPKEY:
2502 case mfDROPLKEY:
2503 case mfDROPCOMPASS:
2504 case mfDROPMAP:
2505 case mfDROPBOSSKEY:
2506 case mfSPAWNNPC:
2507 case mfSWITCHHOOK:
2508 case mfSIDEVIEWLADDER:
2509 case mfSIDEVIEWPLATFORM:
2510 case mfNOENEMYSPAWN:
2511 case mfENEMYALL:
2512 case mfNOMIRROR:
2513 case mfUNSAFEGROUND:
2514 case mf168:
2515 case mf169:
2516 case mf170:
2517 case mf171:
2518 case mf172:
2519 case mf173:
2520 case mf174:
2521 case mf175:
2522 case mf176:
2523 case mf177:
2524 case mf178:
2525 case mf179:
2526 case mf180:
2527 case mf181:
2528 case mf182:
2529 case mf183:
2530 case mf184:
2531 case mf185:
2532 case mf186:
2533 case mf187:
2534 case mf188:
2535 case mf189:
2536 case mf190:
2537 case mf191:
2538 case mf192:
2539 case mf193:
2540 case mf194:
2541 case mf195:
2542 case mf196:
2543 case mf197:
2544 case mf198:
2545 case mf199:
2546 case mf200:
2547 case mf201:
2548 case mf202:
2549 case mf203:
2550 case mf204:
2551 case mf205:
2552 case mf206:
2553 case mf207:
2554 case mf208:
2555 case mf209:
2556 case mf210:
2557 case mf211:
2558 case mf212:
2559 case mf213:
2560 case mf214:
2561 case mf215:
2562 case mf216:
2563 case mf217:
2564 case mf218:
2565 case mf219:
2566 case mf220:
2567 case mf221:
2568 case mf222:
2569 case mf223:
2570 case mf224:
2571 case mf225:
2572 case mf226:
2573 case mf227:
2574 case mf228:
2575 case mf229:
2576 case mf230:
2577 case mf231:
2578 case mf232:
2579 case mf233:
2580 case mf234:
2581 case mf235:
2582 case mf236:
2583 case mf237:
2584 case mf238:
2585 case mf239:
2586 case mf240:
2587 case mf241:
2588 case mf242:
2589 case mf243:
2590 case mf244:
2591 case mf245:
2592 case mf246:
2593 case mf247:
2594 case mf248:
2595 case mf249:
2596 case mf250:
2597 case mf251:
2598 case mf252:
2599 case mf253:
2600 case mf254:
2601 case mfEXTENDED:
2602 6911766 break;
2603
2604 case mfPUSHUD:
2605 case mfPUSHLR:
2606 case mfPUSH4:
2607 case mfPUSHU:
2608 case mfPUSHD:
2609 case mfPUSHL:
2610 case mfPUSHR:
2611 case mfPUSHUDNS:
2612 case mfPUSHLRNS:
2613 case mfPUSH4NS:
2614 case mfPUSHUNS:
2615 case mfPUSHDNS:
2616 case mfPUSHLNS:
2617 case mfPUSHRNS:
2618 case mfPUSHUDINS:
2619 case mfPUSHLRINS:
2620 case mfPUSH4INS:
2621 case mfPUSHUINS:
2622 case mfPUSHDINS:
2623 case mfPUSHLINS:
2624 case mfPUSHRINS:
2625
3/4
✓ Branch 0 taken 1939 times.
✓ Branch 1 taken 1319 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1939 times.
3258 if(!hints && ((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&16))
2626
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 1939 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1939 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1939 || ((get_debug() && zc_getkey(KEY_N)) && (frame&16))))
2627 {
2628 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->undercombo,scr->undercset);
2629 }
2630
2631
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3258 times.
3258 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2632
3/6
✓ Branch 0 taken 2520 times.
✓ Branch 1 taken 738 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 738 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
3258 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2633 {
2634
2/2
✓ Branch 0 taken 1488 times.
✓ Branch 1 taken 1032 times.
2520 if(hints)
2635 {
2636
3/3
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 63 times.
✓ Branch 2 taken 897 times.
1032 switch (rpos_handle.ctype())
2637 {
2638 case cPUSH_HEAVY:
2639 case cPUSH_HW:
2640 72 tempitem=getItemIDPower(itemsbuf,itype_bracelet,1);
2641 144 tempitemx=x, tempitemy=y;
2642
2643
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(tempitem>-1)
2644 72 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2645
2646 72 break;
2647
2648 case cPUSH_HEAVY2:
2649 case cPUSH_HW2:
2650 63 tempitem=getItemIDPower(itemsbuf,itype_bracelet,2);
2651 126 tempitemx=x, tempitemy=y;
2652
2653
1/2
✓ Branch 0 taken 63 times.
✗ Branch 1 not taken.
63 if(tempitem>-1)
2654 63 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2655
2656 63 break;
2657 }
2658 1032 }
2659 2520 }
2660
2661 3258 break;
2662
2663 case mfWHISTLE:
2664
1/2
✓ Branch 0 taken 2418 times.
✗ Branch 1 not taken.
2418 if(hints)
2665 {
2666 tempitem=getItemID(itemsbuf,itype_whistle,1);
2667
2668 if(tempitem<0) break;
2669
2670 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2671 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2672 {
2673 tempitemx=x;
2674 tempitemy=y;
2675 }
2676
2677 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2678 }
2679
2680 2418 break;
2681
2682 //Why is this here?
2683 case mfFAIRY:
2684 case mfMAGICFAIRY:
2685 case mfALLFAIRY:
2686 if(hints)
2687 {
2688 tempitem=getItemID(itemsbuf, itype_fairy,1);//iFairyMoving;
2689
2690 if(tempitem < 0) break;
2691
2692 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2693 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2694 {
2695 tempitemx=x;
2696 tempitemy=y;
2697 }
2698
2699 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2700 }
2701
2702 break;
2703
2704 case mfANYFIRE:
2705
2/2
✓ Branch 0 taken 252 times.
✓ Branch 1 taken 252 times.
504 if(!hints)
2706 {
2707
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sBCANDLE],scr->secretcset[sBCANDLE]);
2708 252 }
2709 else
2710 {
2711 252 tempitem=getItemID(itemsbuf,itype_candle,1);
2712
2713
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(tempitem<0) break;
2714
2715
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2716
3/6
✓ Branch 0 taken 189 times.
✓ Branch 1 taken 63 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 63 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
252 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2717 {
2718 189 tempitemx=x;
2719 189 tempitemy=y;
2720 189 }
2721
2722 252 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2723 }
2724
2725 504 break;
2726
2727 case mfSTRONGFIRE:
2728 if(!hints)
2729 {
2730 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sRCANDLE],scr->secretcset[sRCANDLE]);
2731 }
2732 else
2733 {
2734 tempitem=getItemID(itemsbuf,itype_candle,2);
2735
2736 if(tempitem<0) break;
2737
2738 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2739 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2740 {
2741 tempitemx=x;
2742 tempitemy=y;
2743 }
2744
2745 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2746 }
2747
2748 break;
2749
2750 case mfMAGICFIRE:
2751 if(!hints)
2752 {
2753 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWANDFIRE],scr->secretcset[sWANDFIRE]);
2754 }
2755 else
2756 {
2757 tempitem=getItemID(itemsbuf,itype_wand,1);
2758
2759 if(tempitem<0) break;
2760
2761 tempweapon=wFire;
2762
2763 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2764 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2765 {
2766 tempitemx=x;
2767 tempitemy=y;
2768 }
2769 else
2770 {
2771 tempweaponx=x;
2772 tempweapony=y;
2773 }
2774
2775 putweapon(dest,tempweaponx,tempweapony,tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2776 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2777 }
2778
2779 break;
2780
2781 case mfDIVINEFIRE:
2782 if(!hints)
2783 {
2784 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sDIVINEFIRE],scr->secretcset[sDIVINEFIRE]);
2785 }
2786 else
2787 {
2788 tempitem=getItemID(itemsbuf,itype_divinefire,1);
2789
2790 if(tempitem<0) break;
2791
2792 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2793 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2794 {
2795 tempitemx=x;
2796 tempitemy=y;
2797 }
2798
2799 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2800 }
2801
2802 break;
2803
2804 case mfARROW:
2805
2/2
✓ Branch 0 taken 82 times.
✓ Branch 1 taken 732 times.
814 if(!hints)
2806 {
2807
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 732 times.
732 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sARROW],scr->secretcset[sARROW]);
2808 732 }
2809 else
2810 {
2811 82 tempitem=getItemID(itemsbuf,itype_arrow,1);
2812
2813
1/2
✓ Branch 0 taken 82 times.
✗ Branch 1 not taken.
82 if(tempitem<0) break;
2814
2815
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 82 times.
82 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2816
3/6
✓ Branch 0 taken 61 times.
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 21 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
82 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2817 {
2818 61 tempitemx=x;
2819 61 tempitemy=y;
2820 61 }
2821
2822 82 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2823 }
2824
2825 814 break;
2826
2827 case mfSARROW:
2828 if(!hints)
2829 {
2830 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSARROW],scr->secretcset[sSARROW]);
2831 }
2832 else
2833 {
2834 tempitem=getItemID(itemsbuf,itype_arrow,2);
2835
2836 if(tempitem<0) break;
2837
2838 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2839 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2840 {
2841 tempitemx=x;
2842 tempitemy=y;
2843 }
2844
2845 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2846 }
2847
2848 break;
2849
2850 case mfGARROW:
2851 if(!hints)
2852 {
2853 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sGARROW],scr->secretcset[sGARROW]);
2854 }
2855 else
2856 {
2857 tempitem=getItemID(itemsbuf,itype_arrow,3);
2858
2859 if(tempitem<0) break;
2860
2861 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2862 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2863 {
2864 tempitemx=x;
2865 tempitemy=y;
2866 }
2867
2868 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2869 }
2870
2871 break;
2872
2873 case mfBOMB:
2874
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 76 times.
93 if(!hints)
2875 {
2876
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 76 times.
76 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sBOMB],scr->secretcset[sBOMB]);
2877 76 }
2878 else
2879 {
2880 //tempitem=getItemID(itemsbuf,itype_bomb,1);
2881 17 tempweapon = wLitBomb;
2882
2883 //if (tempitem<0) break;
2884
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2885
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2886 {
2887 12 tempweaponx=x;
2888 12 tempweapony=y;
2889 12 }
2890
2891 17 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2892 }
2893
2894 93 break;
2895
2896 case mfSBOMB:
2897
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 48 times.
96 if(!hints)
2898 {
2899
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSBOMB],scr->secretcset[sSBOMB]);
2900 48 }
2901 else
2902 {
2903 //tempitem=getItemID(itemsbuf,itype_sbomb,1);
2904 //if (tempitem<0) break;
2905 48 tempweapon = wLitSBomb;
2906
2907
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2908
3/6
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
48 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2909 {
2910 36 tempweaponx=x;
2911 36 tempweapony=y;
2912 36 }
2913
2914 48 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2915 }
2916
2917 96 break;
2918
2919 case mfARMOS_SECRET:
2920
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
24 if(!hints)
2921 {
2922
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
2923 36 putcombo(dest,x,y,scr->secretcombo[sSTAIRS],scr->secretcset[sSTAIRS]);
2924 12 }
2925 24 break;
2926
2927 case mfBRANG:
2928
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 20 times.
25 if(!hints)
2929 {
2930
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
2931 60 putcombo(dest,x,y,scr->secretcombo[sBRANG],scr->secretcset[sBRANG]);
2932 20 }
2933 else
2934 {
2935 5 tempitem=getItemID(itemsbuf,itype_brang,1);
2936
2937
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(tempitem<0) break;
2938
2939
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2940
3/6
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
5 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2941 {
2942 4 tempitemx=x;
2943 4 tempitemy=y;
2944 4 }
2945
2946 5 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2947 }
2948
2949 25 break;
2950
2951 case mfMBRANG:
2952 if(!hints)
2953 {
2954 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sMBRANG],scr->secretcset[sMBRANG]);
2955 }
2956 else
2957 {
2958 tempitem=getItemID(itemsbuf,itype_brang,2);
2959
2960 if(tempitem<0) break;
2961
2962 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2963 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2964 {
2965 tempitemx=x;
2966 tempitemy=y;
2967 }
2968
2969 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2970 }
2971
2972 break;
2973
2974 case mfFBRANG:
2975 if(!hints)
2976 {
2977 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sFBRANG],scr->secretcset[sFBRANG]);
2978 }
2979 else
2980 {
2981 tempitem=getItemID(itemsbuf,itype_brang,3);
2982
2983 if(tempitem<0) break;
2984
2985 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2986 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2987 {
2988 tempitemx=x;
2989 tempitemy=y;
2990 }
2991
2992 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2993 }
2994
2995 break;
2996
2997 case mfWANDMAGIC:
2998
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 138 times.
138 if(!hints)
2999 {
3000
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 138 times.
138 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWANDMAGIC],scr->secretcset[sWANDMAGIC]);
3001 138 }
3002 else
3003 {
3004 tempitem=getItemID(itemsbuf,itype_wand,1);
3005
3006 if(tempitem<0) break;
3007
3008 tempweapon=itemsbuf[tempitem].wpn3;
3009
3010 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3011 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3012 {
3013 tempitemx=x;
3014 tempitemy=y;
3015 }
3016 else
3017 {
3018 tempweaponx=x;
3019 tempweapony=y;
3020 --lens_hint_weapon[wMagic][4];
3021
3022 if(lens_hint_weapon[wMagic][4]<-8)
3023 {
3024 lens_hint_weapon[wMagic][4]=8;
3025 }
3026 }
3027
3028 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3029 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3030 }
3031
3032 138 break;
3033
3034 case mfREFMAGIC:
3035
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3036 {
3037 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sREFMAGIC],scr->secretcset[sREFMAGIC]);
3038 }
3039 else
3040 {
3041 16 tempitem=getItemID(itemsbuf,itype_shield,3);
3042
3043
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3044
3045 16 tempweapon=ewMagic;
3046
3047
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3048
3/6
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3049 {
3050 13 tempitemx=x;
3051 13 tempitemy=y;
3052 13 }
3053 else
3054 {
3055 3 tempweaponx=x;
3056 3 tempweapony=y;
3057
3058
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if(lens_hint_weapon[ewMagic][2]==up)
3059 {
3060 1 --lens_hint_weapon[ewMagic][4];
3061 1 }
3062 else
3063 {
3064 2 ++lens_hint_weapon[ewMagic][4];
3065 }
3066
3067
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(lens_hint_weapon[ewMagic][4]>8)
3068 {
3069 lens_hint_weapon[ewMagic][2]=up;
3070 }
3071
3072
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if(lens_hint_weapon[ewMagic][4]<=0)
3073 {
3074 2 lens_hint_weapon[ewMagic][2]=down;
3075 2 }
3076 }
3077
3078 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3079 16 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, lens_hint_weapon[ewMagic][2], lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3080 }
3081
3082 16 break;
3083
3084 case mfREFFIREBALL:
3085
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3086 {
3087 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sREFFIREBALL],scr->secretcset[sREFFIREBALL]);
3088 }
3089 else
3090 {
3091 16 tempitem=getItemID(itemsbuf,itype_shield,3);
3092
3093
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3094
3095 16 tempweapon=ewFireball;
3096
3097
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3098
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3099 {
3100 12 tempitemx=x;
3101 12 tempitemy=y;
3102 12 tempweaponx=x;
3103 12 tempweapony=y;
3104 12 ++lens_hint_weapon[ewFireball][3];
3105
3106
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 1 times.
12 if(lens_hint_weapon[ewFireball][3]>8)
3107 {
3108 1 lens_hint_weapon[ewFireball][3]=-8;
3109 1 lens_hint_weapon[ewFireball][4]=8;
3110 1 }
3111
3112
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4 times.
12 if(lens_hint_weapon[ewFireball][3]>0)
3113 {
3114 8 ++lens_hint_weapon[ewFireball][4];
3115 8 }
3116 else
3117 {
3118 4 --lens_hint_weapon[ewFireball][4];
3119 }
3120 12 }
3121
3122 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3123 16 putweapon(dest,tempweaponx+lens_hint_weapon[tempweapon][3],tempweapony+lens_hint_weapon[ewFireball][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3124 }
3125
3126 16 break;
3127
3128 case mfSWORD:
3129
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(!hints)
3130 {
3131 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSWORD],scr->secretcset[sSWORD]);
3132 }
3133 else
3134 {
3135 7 tempitem=getItemID(itemsbuf,itype_sword,1);
3136
3137
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(tempitem<0) break;
3138
3139
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3140
3/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
7 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3141 {
3142 5 tempitemx=x;
3143 5 tempitemy=y;
3144 5 }
3145
3146 7 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3147 }
3148
3149 7 break;
3150
3151 case mfWSWORD:
3152 if(!hints)
3153 {
3154 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWSWORD],scr->secretcset[sWSWORD]);
3155 }
3156 else
3157 {
3158 tempitem=getItemID(itemsbuf,itype_sword,2);
3159
3160 if(tempitem<0) break;
3161
3162 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3163 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3164 {
3165 tempitemx=x;
3166 tempitemy=y;
3167 }
3168
3169 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3170 }
3171
3172 break;
3173
3174 case mfMSWORD:
3175 if(!hints)
3176 {
3177 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sMSWORD],scr->secretcset[sMSWORD]);
3178 }
3179 else
3180 {
3181 tempitem=getItemID(itemsbuf,itype_sword,3);
3182
3183 if(tempitem<0) break;
3184
3185 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3186 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3187 {
3188 tempitemx=x;
3189 tempitemy=y;
3190 }
3191
3192 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3193 }
3194
3195 break;
3196
3197 case mfXSWORD:
3198 if(!hints)
3199 {
3200 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sXSWORD],scr->secretcset[sXSWORD]);
3201 }
3202 else
3203 {
3204 tempitem=getItemID(itemsbuf,itype_sword,4);
3205
3206 if(tempitem<0) break;
3207
3208 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3209 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3210 {
3211 tempitemx=x;
3212 tempitemy=y;
3213 }
3214
3215 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3216 }
3217
3218 break;
3219
3220 case mfSWORDBEAM:
3221
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3222 {
3223 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSWORDBEAM],scr->secretcset[sSWORDBEAM]);
3224 }
3225 else
3226 {
3227 16 tempitem=getItemID(itemsbuf,itype_sword,1);
3228
3229
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3230
3231
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3232
3/6
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3233 {
3234 11 tempitemx=x;
3235 11 tempitemy=y;
3236 11 }
3237
3238 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 1);
3239 }
3240
3241 16 break;
3242
3243 case mfWSWORDBEAM:
3244 if(!hints)
3245 {
3246 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWSWORDBEAM],scr->secretcset[sWSWORDBEAM]);
3247 }
3248 else
3249 {
3250 tempitem=getItemID(itemsbuf,itype_sword,2);
3251
3252 if(tempitem<0) break;
3253
3254 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3255 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3256 {
3257 tempitemx=x;
3258 tempitemy=y;
3259 }
3260
3261 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 2);
3262 }
3263
3264 break;
3265
3266 case mfMSWORDBEAM:
3267 if(!hints)
3268 {
3269 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sMSWORDBEAM],scr->secretcset[sMSWORDBEAM]);
3270 }
3271 else
3272 {
3273 tempitem=getItemID(itemsbuf,itype_sword,3);
3274
3275 if(tempitem<0) break;
3276
3277 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3278 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3279 {
3280 tempitemx=x;
3281 tempitemy=y;
3282 }
3283
3284 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 3);
3285 }
3286
3287 break;
3288
3289 case mfXSWORDBEAM:
3290 if(!hints)
3291 {
3292 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sXSWORDBEAM],scr->secretcset[sXSWORDBEAM]);
3293 }
3294 else
3295 {
3296 tempitem=getItemID(itemsbuf,itype_sword,4);
3297
3298 if(tempitem<0) break;
3299
3300 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3301 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3302 {
3303 tempitemx=x;
3304 tempitemy=y;
3305 }
3306
3307 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 4);
3308 }
3309
3310 break;
3311
3312 case mfHOOKSHOT:
3313
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(!hints)
3314 {
3315 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sHOOKSHOT],scr->secretcset[sHOOKSHOT]);
3316 }
3317 else
3318 {
3319 17 tempitem=getItemID(itemsbuf,itype_hookshot,1);
3320
3321
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(tempitem<0) break;
3322
3323
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3324
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3325 {
3326 12 tempitemx=x;
3327 12 tempitemy=y;
3328 12 }
3329
3330 17 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3331 }
3332
3333 17 break;
3334
3335 case mfWAND:
3336
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if(!hints)
3337 {
3338 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWAND],scr->secretcset[sWAND]);
3339 }
3340 else
3341 {
3342 35 tempitem=getItemID(itemsbuf,itype_wand,1);
3343
3344
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if(tempitem<0) break;
3345
3346
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
35 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3347
3/6
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
35 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3348 {
3349 28 tempitemx=x;
3350 28 tempitemy=y;
3351 28 }
3352
3353 35 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3354 }
3355
3356 35 break;
3357
3358 case mfHAMMER:
3359
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(!hints)
3360 {
3361 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sHAMMER],scr->secretcset[sHAMMER]);
3362 }
3363 else
3364 {
3365 17 tempitem=getItemID(itemsbuf,itype_hammer,1);
3366
3367
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(tempitem<0) break;
3368
3369
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3370
3/6
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3371 {
3372 13 tempitemx=x;
3373 13 tempitemy=y;
3374 13 }
3375
3376 17 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3377 }
3378
3379 17 break;
3380
3381 case mfARMOS_ITEM:
3382 case mfDIVE_ITEM:
3383
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2602 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2602 times.
2602 if((!getmapflag(scr, mSPECIALITEM) || (scr->flags9&fBELOWRETURN)) && !(itemsbuf[Hero.getLastLensID()].flags & item_flag3))
3384 {
3385 7806 putitem2(dest,x,y,scr->catchall, lens_hint_item[scr->catchall][0], lens_hint_item[scr->catchall][1], 0);
3386 2602 }
3387 2602 break;
3388
3389 case 16:
3390 case 17:
3391 case 18:
3392 case 19:
3393 case 20:
3394 case 21:
3395 case 22:
3396 case 23:
3397 case 24:
3398 case 25:
3399 case 26:
3400 case 27:
3401 case 28:
3402 case 29:
3403 case 30:
3404 case 31:
3405
2/2
✓ Branch 0 taken 1008 times.
✓ Branch 1 taken 107890 times.
108898 if(!hints)
3406
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 107890 times.
215780 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3407 323670 putcombo(dest,x,y,scr->secretcombo[checkflag-16+4],scr->secretcset[checkflag-16+4]);
3408
3409 108898 break;
3410 case mfSECRETSNEXT:
3411 if(!hints)
3412 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3413 putcombo(dest,x,y,rpos_handle.data()+1,rpos_handle.cset());
3414
3415 break;
3416
3417 case mfSTRIKE:
3418
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3419 {
3420 906 goto special;
3421 }
3422 else
3423 {
3424 break;
3425 }
3426
3427 28750 default: goto special;
3428
3429 special:
3430
8/8
✓ Branch 0 taken 14732 times.
✓ Branch 1 taken 14924 times.
✓ Branch 2 taken 528 times.
✓ Branch 3 taken 14204 times.
✓ Branch 4 taken 496 times.
✓ Branch 5 taken 32 times.
✓ Branch 6 taken 6108 times.
✓ Branch 7 taken 8128 times.
29656 if(layer && ((checkflag!=mfRAFT && checkflag!=mfRAFT_BRANCH&& checkflag!=mfRAFT_BOUNCE) ||(itemsbuf[Hero.getLastLensID()].flags & item_flag4)))
3431 {
3432
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 6604 times.
✓ Branch 2 taken 4954 times.
✓ Branch 3 taken 1650 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1650 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
6604 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate)) || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3433 {
3434 24770 rectfill(dest,x,y,x+15,y+15,WHITE);
3435 4954 }
3436 6604 }
3437
3438 29656 break;
3439 }
3440 7060416 }
3441 3530208 });
3442
3443 40116 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
3444 90824 auto [offx, offy] = translate_screen_coordinates_to_world(scr->screen);
3445
3446 40116 offx -= viewport.x;
3447 40116 offy -= viewport.y;
3448 40116 offy += playing_field_offset;
3449
3450
2/2
✓ Branch 0 taken 10029 times.
✓ Branch 1 taken 10029 times.
20058 if (layer)
3451 {
3452
2/2
✓ Branch 0 taken 9670 times.
✓ Branch 1 taken 359 times.
10029 if (scr->door[0]==dWALK)
3453 1795 rectfill(dest, 120+offx, 16+offy, 135+offx, 31+offy, WHITE);
3454
3455
2/2
✓ Branch 0 taken 9606 times.
✓ Branch 1 taken 423 times.
10029 if (scr->door[1]==dWALK)
3456 2115 rectfill(dest, 120+offx, 144+offy, 135+offx, 159+offy, WHITE);
3457
3458
2/2
✓ Branch 0 taken 9447 times.
✓ Branch 1 taken 582 times.
10029 if (scr->door[2]==dWALK)
3459 2910 rectfill(dest, 16+offx, 80+offy, 31+offx, 95+offy, WHITE);
3460
3461
2/2
✓ Branch 0 taken 9405 times.
✓ Branch 1 taken 624 times.
10029 if (scr->door[3]==dWALK)
3462 3120 rectfill(dest, 224+offx, 80+offy, 239+offx, 95+offy, WHITE);
3463
3464
2/2
✓ Branch 0 taken 9986 times.
✓ Branch 1 taken 43 times.
10029 if (scr->door[0]==dBOMB)
3465 {
3466 129 showbombeddoor(scr, dest, 0, offx, offy);
3467 43 }
3468
3469
2/2
✓ Branch 0 taken 9990 times.
✓ Branch 1 taken 39 times.
10029 if (scr->door[1]==dBOMB)
3470 {
3471 117 showbombeddoor(scr, dest, 1, offx, offy);
3472 39 }
3473
3474
2/2
✓ Branch 0 taken 10023 times.
✓ Branch 1 taken 6 times.
10029 if (scr->door[2]==dBOMB)
3475 {
3476 18 showbombeddoor(scr, dest, 2, offx, offy);
3477 6 }
3478
3479
2/2
✓ Branch 0 taken 9992 times.
✓ Branch 1 taken 37 times.
10029 if (scr->door[3]==dBOMB)
3480 {
3481 111 showbombeddoor(scr, dest, 3, offx, offy);
3482 37 }
3483 10029 }
3484
3485
3/4
✓ Branch 0 taken 18024 times.
✓ Branch 1 taken 2034 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18024 times.
20058 if (scr->stairx || scr->stairy)
3486 {
3487
2/2
✓ Branch 0 taken 911 times.
✓ Branch 1 taken 1123 times.
2034 if (!hints)
3488 {
3489
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1123 times.
1123 if (!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3490 3369 putcombo(dest,scr->stairx+offx,scr->stairy+offy,scr->secretcombo[sSTAIRS],scr->secretcset[sSTAIRS]);
3491 1123 }
3492 else
3493 {
3494
2/2
✓ Branch 0 taken 863 times.
✓ Branch 1 taken 48 times.
911 if(scr->flags&fWHISTLE)
3495 {
3496 48 tempitem=getItemID(itemsbuf,itype_whistle,1);
3497 48 int32_t tempitemx=-16+offx;
3498 48 int32_t tempitemy=-16+offy-playing_field_offset;
3499
3500
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if ((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&(blink_rate/4)))
3501
3/6
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
48 || ((get_debug() && zc_getkey(KEY_N)) && (frame&(blink_rate/4))))
3502 {
3503 48 tempitemx=scr->stairx+offx;
3504 48 tempitemy=scr->stairy+offy;
3505 24 }
3506
3507 48 putitem2(dest, tempitemx, tempitemy, tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3508 48 }
3509 }
3510 2034 }
3511 20058 });
3512 }
3513 20058 }
3514
3515 9690 void draw_lens_over()
3516 {
3517 9690 int w = 288;
3518 9690 int h = 240;
3519
3520
4/6
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9672 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18 times.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
9690 static BITMAP *lens_scr = create_bitmap_ex(8,2*w,2*h);
3521 static int32_t last_width = -1;
3522 9690 int32_t width = itemsbuf[current_item_id(itype_lens,true)].misc1;
3523
3524 // Only redraw the circle if the size has changed
3525
2/2
✓ Branch 0 taken 9670 times.
✓ Branch 1 taken 20 times.
9690 if (width != last_width)
3526 {
3527 20 clear_to_color(lens_scr, BLACK);
3528 20 circlefill(lens_scr, w, h, width, 0);
3529 20 circle(lens_scr, w, h, width+2, 0);
3530 20 circle(lens_scr, w, h, width+5, 0);
3531 20 last_width=width;
3532 20 }
3533
3534 9690 masked_blit(lens_scr, framebuf, w-(HeroX()+8)+viewport.x, h-(HeroY()+8)+viewport.y, 0, playing_field_offset, 256, viewport.h);
3535 9690 do_primitives(framebuf, SPLAYER_LENS_OVER);
3536 9690 }
3537
3538 37083794 static void update_bmp_size(BITMAP** bmp_ptr, int w, int h)
3539 {
3540 37083794 BITMAP* bmp = *bmp_ptr;
3541
3/4
✓ Branch 0 taken 37083794 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 37083788 times.
✓ Branch 3 taken 6 times.
37083794 if (bmp->w == w && bmp->h == h)
3542 37083788 return;
3543
3544 6 int depth = bitmap_color_depth(bmp);
3545 6 destroy_bitmap(bmp);
3546 6 *bmp_ptr = create_bitmap_ex(depth, w, h);
3547 37083794 }
3548
3549 32148 void draw_wavy(BITMAP *source, BITMAP *target, int32_t amplitude, bool interpol)
3550 {
3551
4/6
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 32142 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
32148 static BITMAP *wavebuf = create_bitmap_ex(8,288,240-original_playing_field_offset);
3552 32148 update_bmp_size(&wavebuf, 288, 240 - original_playing_field_offset);
3553
3554 32148 clear_to_color(wavebuf, BLACK);
3555 32148 blit(source,wavebuf,0,original_playing_field_offset,16,0,256,framebuf->h-original_playing_field_offset);
3556
3557 int32_t ofs;
3558
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32148 times.
32148 amplitude = zc_min(2048,amplitude); // some arbitrary limit to prevent crashing
3559
4/6
✓ Branch 0 taken 32148 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 32148 times.
✓ Branch 4 taken 662 times.
✓ Branch 5 taken 31486 times.
32148 if(flash_reduction_enabled() && !get_qr(qr_WAVY_NO_EPILEPSY)) amplitude = zc_min(16,amplitude);
3560 32148 int32_t amp2 = viewport.visible_height(show_bottom_8px);
3561
2/4
✓ Branch 0 taken 32148 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 32148 times.
32148 if(flash_reduction_enabled() && !get_qr(qr_WAVY_NO_EPILEPSY_2)) amp2*=2;
3562 32148 int32_t i=frame%amp2;
3563
3564
2/2
✓ Branch 0 taken 5403672 times.
✓ Branch 1 taken 32148 times.
5435820 for(int32_t j=0; j<viewport.visible_height(show_bottom_8px); j++)
3565 {
3566
3/4
✓ Branch 0 taken 2701836 times.
✓ Branch 1 taken 2701836 times.
✓ Branch 2 taken 2701836 times.
✗ Branch 3 not taken.
5403672 if(j&1 && interpol)
3567 {
3568 // Add 288*2048 to ensure it's never negative. It'll get modded out.
3569 ofs=288*2048+int32_t(zc::math::Sin((double(i+j)*2*PI/amp2))*amplitude);
3570 }
3571 else
3572 {
3573 5403672 ofs=288*2048-int32_t(zc::math::Sin((double(i+j)*2*PI/amp2))*amplitude);
3574 }
3575
3576
1/2
✓ Branch 0 taken 5403672 times.
✗ Branch 1 not taken.
5403672 if(ofs)
3577 {
3578
2/2
✓ Branch 0 taken 1383340032 times.
✓ Branch 1 taken 5403672 times.
1388743704 for(int32_t k=0; k<256; k++)
3579 {
3580 1383340032 target->line[j+original_playing_field_offset][k]=wavebuf->line[j][(k+ofs+16)%288];
3581 1383340032 }
3582 5403672 }
3583 5403672 }
3584 32148 }
3585
3586 28272 void draw_fuzzy(int32_t fuzz)
3587 // draws from right half of scrollbuf to framebuf
3588 {
3589 int32_t firstx, firsty, xstep, ystep, i, y, dx, dy;
3590 byte *start, *si, *di;
3591
3592
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28272 times.
28272 if(fuzz<1)
3593 fuzz = 1;
3594
3595 28272 xstep = 128%fuzz;
3596
3597
2/2
✓ Branch 0 taken 5890 times.
✓ Branch 1 taken 22382 times.
28272 if(xstep > 0)
3598 22382 xstep = fuzz-xstep;
3599
3600 28272 ystep = 112%fuzz;
3601
3602
2/2
✓ Branch 0 taken 8246 times.
✓ Branch 1 taken 20026 times.
28272 if(ystep > 0)
3603 20026 ystep = fuzz-ystep;
3604
3605 28272 firsty = 1;
3606
3607
2/2
✓ Branch 0 taken 28272 times.
✓ Branch 1 taken 1020148 times.
1048420 for(y=0; y<framebuf->h;)
3608 {
3609 1020148 start = &(scrollbuf_old->line[y][256]);
3610
3611
4/4
✓ Branch 0 taken 1006012 times.
✓ Branch 1 taken 6347064 times.
✓ Branch 2 taken 6332928 times.
✓ Branch 3 taken 1020148 times.
7353076 for(dy=0; dy<ystep && dy+y<framebuf->h; dy++)
3612 {
3613 6332928 si = start;
3614 6332928 di = &(framebuf->line[y+dy][0]);
3615 6332928 i = xstep;
3616 6332928 firstx = 1;
3617
3618
2/2
✓ Branch 0 taken 1621229568 times.
✓ Branch 1 taken 6332928 times.
1627562496 for(dx=0; dx<framebuf->w; dx++)
3619 {
3620 1621229568 *(di++) = *si;
3621
3622
2/2
✓ Branch 0 taken 1366065344 times.
✓ Branch 1 taken 255164224 times.
1621229568 if(++i >= fuzz)
3623 {
3624
2/2
✓ Branch 0 taken 248831296 times.
✓ Branch 1 taken 6332928 times.
255164224 if(!firstx)
3625 248831296 si += fuzz;
3626 else
3627 {
3628 6332928 si += fuzz-xstep;
3629 6332928 firstx = 0;
3630 }
3631
3632 255164224 i = 0;
3633 255164224 }
3634 1621229568 }
3635 6332928 }
3636
3637
2/2
✓ Branch 0 taken 991876 times.
✓ Branch 1 taken 28272 times.
1020148 if(!firsty)
3638 991876 y += fuzz;
3639 else
3640 {
3641 28272 y += ystep;
3642 28272 ystep = fuzz;
3643 28272 firsty = 0;
3644 }
3645 }
3646 28272 }
3647
3648 18525823 void updatescr(bool allowwavy)
3649 {
3650
4/6
✓ Branch 0 taken 312 times.
✓ Branch 1 taken 18525511 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 312 times.
✓ Branch 4 taken 312 times.
✗ Branch 5 not taken.
18525823 static BITMAP *wavybuf = create_bitmap_ex(8, framebuf->w, framebuf->h);
3651
4/6
✓ Branch 0 taken 312 times.
✓ Branch 1 taken 18525511 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 312 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 312 times.
18525823 static BITMAP *panorama = create_bitmap_ex(8, framebuf->w, framebuf->h);
3652 18525823 update_bmp_size(&wavybuf, framebuf->w, framebuf->h);
3653 18525823 update_bmp_size(&panorama, framebuf->w, framebuf->h);
3654
3655
2/2
✓ Branch 0 taken 18497722 times.
✓ Branch 1 taken 28101 times.
18525823 if(toogam)
3656 {
3657 28101 textout_ex(framebuf,font,"no walls",8,216,1,-1);
3658 28101 }
3659
3660
1/2
✓ Branch 0 taken 18525823 times.
✗ Branch 1 not taken.
18525823 if(Showpal)
3661 dump_pal(framebuf);
3662
3663
2/2
✓ Branch 0 taken 18010060 times.
✓ Branch 1 taken 515763 times.
18525823 if(!Playing)
3664 515763 black_opening_count=0;
3665
3666
2/2
✓ Branch 0 taken 18357499 times.
✓ Branch 1 taken 168324 times.
18525823 if(black_opening_count<0) //shape is opening up
3667 {
3668 168324 black_opening(framebuf,black_opening_x,black_opening_y,(66+black_opening_count),66);
3669
3670
2/4
✓ Branch 0 taken 168324 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 168324 times.
168324 if(Advance||(!Paused))
3671 {
3672 168324 ++black_opening_count;
3673 168324 }
3674 168324 }
3675
2/2
✓ Branch 0 taken 18308725 times.
✓ Branch 1 taken 48774 times.
18357499 else if(black_opening_count>0) //shape is closing
3676 {
3677 48774 black_opening(framebuf,black_opening_x,black_opening_y,black_opening_count,66);
3678
3679
2/4
✓ Branch 0 taken 48774 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 48774 times.
48774 if(Advance||(!Paused))
3680 {
3681 48774 --black_opening_count;
3682 48774 }
3683 48774 }
3684
3685
3/4
✓ Branch 0 taken 18312014 times.
✓ Branch 1 taken 213809 times.
✓ Branch 2 taken 18312014 times.
✗ Branch 3 not taken.
18525823 if(black_opening_count==0&&black_opening_shape==bosFADEBLACK)
3686 {
3687 black_opening_shape = bosCIRCLE;
3688 memcpy(RAMpal, tempblackpal, PAL_SIZE*sizeof(RGB));
3689 refreshTints();
3690 refreshpal=true;
3691 }
3692
3693
2/2
✓ Branch 0 taken 17892832 times.
✓ Branch 1 taken 632991 times.
18525823 if(refreshpal)
3694 {
3695 632991 refreshpal=false;
3696 632991 RAMpal[253] = _RGB(0,0,0);
3697 632991 RAMpal[254] = _RGB(255,255,255);
3698 632991 hw_palette = &RAMpal;
3699 632991 update_hw_pal = true;
3700 632991 refresh_rgb_tables();
3701 632991 }
3702
3703 18525823 bool clearwavy = (wavy <= 0);
3704
3705
2/2
✓ Branch 0 taken 8692 times.
✓ Branch 1 taken 18517131 times.
18525823 if(wavy <= 0)
3706 {
3707 // So far one thing can alter wavy apart from scripts: Wavy DMaps.
3708 18517131 wavy = (DMaps[cur_dmap].flags&dmfWAVY ? 4 : 0);
3709 18517131 }
3710
3711 18525823 blit(framebuf, wavybuf, 0, 0, 0, 0, framebuf->w, framebuf->h);
3712
3713
6/6
✓ Branch 0 taken 32398 times.
✓ Branch 1 taken 18493425 times.
✓ Branch 2 taken 32276 times.
✓ Branch 3 taken 122 times.
✓ Branch 4 taken 128 times.
✓ Branch 5 taken 32148 times.
18525823 if(wavy && Playing && allowwavy)
3714 {
3715 32148 draw_wavy(framebuf, wavybuf, wavy,false);
3716 32148 }
3717
3718
2/2
✓ Branch 0 taken 18517131 times.
✓ Branch 1 taken 8692 times.
18525823 if(clearwavy)
3719 18517131 wavy = 0; // Wavy was set by a DMap flag. Clear it.
3720
2/4
✓ Branch 0 taken 8692 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8692 times.
8692 else if(Playing && !Paused)
3721 8692 wavy--; // Wavy was set by a script. Decrement it.
3722
3723
3/4
✓ Branch 0 taken 18010060 times.
✓ Branch 1 taken 515763 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18010060 times.
18525823 if(Playing && !Paused)
3724 18010060 ++light_wave_clk;
3725
3726
6/6
✓ Branch 0 taken 18010060 times.
✓ Branch 1 taken 515763 times.
✓ Branch 2 taken 260343 times.
✓ Branch 3 taken 17749717 times.
✓ Branch 4 taken 18 times.
✓ Branch 5 taken 260325 times.
18525823 if(Playing && msg_active && !screenscrolling)
3727 {
3728
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 260258 times.
260325 if(!(msg_bg_display_buf->clip))
3729 260258 blit_msgstr_bg(framebuf,0,0,0,playing_field_offset,256,176);
3730
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 260258 times.
260325 if(!(msg_portrait_display_buf->clip))
3731 260258 blit_msgstr_prt(framebuf,0,0,0,playing_field_offset,256,176);
3732
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 260258 times.
260325 if(!(msg_txt_display_buf->clip))
3733 260258 blit_msgstr_fg(framebuf,0,0,0,playing_field_offset,256,176);
3734 260325 }
3735
3736
3/4
✓ Branch 0 taken 18525823 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18332096 times.
✓ Branch 3 taken 193727 times.
18525823 bool nosubscr = GameLoaded && no_subscreen() && !(hero_scr->flags3&fNOSUBSCROFFSET);
3737
3738
2/2
✓ Branch 0 taken 18337369 times.
✓ Branch 1 taken 188454 times.
18525823 if(nosubscr)
3739 {
3740 188454 clear_to_color(panorama, 0);
3741 188454 blit(wavybuf,panorama,0,playing_field_offset,0,playing_field_offset/2,256,framebuf->h-playing_field_offset);
3742 188454 }
3743
3744 //TODO: Optimize blit 'overcalls' -Gleeok
3745
2/2
✓ Branch 0 taken 188454 times.
✓ Branch 1 taken 18337369 times.
18525823 BITMAP *source = nosubscr ? panorama : wavybuf;
3746 18525823 blit(source, framebuf, 0, 0, 0, 0, framebuf->w, framebuf->h);
3747
3748 18525823 update_hw_screen();
3749 18525823 }
3750
3751 //----------------------------------------------------------------
3752
3753 static PALETTE syspal;
3754 int32_t onGUISnapshot()
3755 {
3756 char buf[200];
3757 int32_t num=0;
3758 do
3759 {
3760 sprintf(buf, "%szc_screen%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
3761 }
3762 while(num<99999 && exists(buf));
3763
3764 if (!al_save_bitmap(buf, al_get_backbuffer(all_get_display())))
3765 InfoDialog("Error", "Failed to save snapshot").show();
3766
3767 return D_O_K;
3768 }
3769
3770 int32_t onNonGUISnapshot()
3771 {
3772 PALETTE temppal;
3773 get_palette(temppal);
3774 bool realpal=(zc_getkey(KEY_ZC_LCONTROL, true) || zc_getkey(KEY_ZC_RCONTROL, true));
3775
3776 char buf[200];
3777 int32_t num=0;
3778
3779 do
3780 {
3781 sprintf(buf, "%szc_screen%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
3782 }
3783 while(num<99999 && exists(buf));
3784
3785 if (no_subscreen() && !(hero_scr->flags3&fNOSUBSCROFFSET) && !key[KEY_ALT])
3786 {
3787 BITMAP *b = create_bitmap_ex(8, 256, viewport.visible_height(show_bottom_8px));
3788 clear_to_color(b,0);
3789 blit(framebuf,b,0,playing_field_offset/2,0,0,b->w,b->h);
3790 alleg4_save_bitmap(b, SnapshotScale, buf, realpal ? temppal : RAMpal);
3791 destroy_bitmap(b);
3792 }
3793 else
3794 {
3795 alleg4_save_bitmap(framebuf, SnapshotScale, buf, realpal?temppal:RAMpal);
3796 }
3797
3798 return D_O_K;
3799 }
3800
3801 int32_t onSnapshot()
3802 {
3803 if(zc_getkey(KEY_LSHIFT, true)||zc_getkey(KEY_RSHIFT, true))
3804 {
3805 onGUISnapshot();
3806 }
3807 else
3808 {
3809 onNonGUISnapshot();
3810 }
3811
3812 return D_O_K;
3813 }
3814
3815 int32_t onSaveMapPic()
3816 {
3817 char buf[200];
3818 int32_t num=0;
3819 BITMAP* _screen_draw_buffer = NULL;
3820 _screen_draw_buffer = create_bitmap_ex(8,256,176);
3821
3822 do
3823 {
3824 sprintf(buf, "%szc_screen%05d.png", get_snap_str(), ++num);
3825 }
3826 while(num<99999 && exists(buf));
3827
3828 BITMAP* mappic = create_bitmap_ex(8,(256*16),(176*8));
3829 clear_to_color(mappic, BLACK);
3830
3831 if(!mappic)
3832 {
3833 enter_sys_pal();
3834 jwin_alert("View Map","Not enough memory.",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
3835 exit_sys_pal();
3836 return D_O_K;;
3837 }
3838
3839 clear_to_color(_screen_draw_buffer, BLACK);
3840
3841 auto prev_viewport = viewport;
3842 viewport.x = 0;
3843 viewport.y = 0;
3844
3845 // draw the map
3846
3847 for(int32_t y=0; y<8; y++)
3848 {
3849 for(int32_t x=0; x<16; x++)
3850 {
3851 if (!displayOnMap(x, y))
3852 continue;
3853
3854 int screen = map_scr_xy_to_index(x, y);
3855 auto scrs = loadscr2(screen);
3856 mapscr* scr = &scrs[0];
3857 if (!scr->is_valid())
3858 continue;
3859
3860 screen_handles_t screen_handles;
3861 for (int i = 0; i <= 6; i++)
3862 screen_handles[i] = {scr, scrs[i].is_valid() ? &scrs[i] : nullptr, screen, i};
3863
3864 int xx = 0;
3865 int yy = -playing_field_offset;
3866
3867 if(XOR(scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
3868 {
3869 do_layer(_screen_draw_buffer, 0, screen_handles[2], xx, yy);
3870 do_ffc_layer(_screen_draw_buffer, -2, screen_handles[0], xx, yy);
3871 }
3872
3873 if(XOR(scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
3874 {
3875 do_layer(_screen_draw_buffer, 0, screen_handles[3], xx, yy);
3876 do_ffc_layer(_screen_draw_buffer, -3, screen_handles[0], xx, yy);
3877 }
3878
3879 if(lenscheck(scr,0))
3880 putscr(scr, _screen_draw_buffer, 0, 0);
3881 do_ffc_layer(_screen_draw_buffer, 0, screen_handles[0], xx, yy);
3882 do_layer(_screen_draw_buffer, 0, screen_handles[1], xx, yy);
3883 do_ffc_layer(_screen_draw_buffer, 1, screen_handles[0], xx, yy);
3884
3885 if(!XOR(scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
3886 {
3887 do_layer(_screen_draw_buffer, 0, screen_handles[2], xx, yy);
3888 do_ffc_layer(_screen_draw_buffer, 2, screen_handles[0], xx, yy);
3889 }
3890
3891 putscrdoors(scr, _screen_draw_buffer, xx, yy);
3892 if(get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
3893 {
3894 do_layer(_screen_draw_buffer, -2, screen_handles[0], xx, yy);
3895 if(get_qr(qr_PUSHBLOCK_LAYER_1_2))
3896 {
3897 do_layer(_screen_draw_buffer, -2, screen_handles[1], xx, yy);
3898 do_layer(_screen_draw_buffer, -2, screen_handles[2], xx, yy);
3899 }
3900 }
3901
3902 if(!XOR(scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
3903 {
3904 do_layer(_screen_draw_buffer, 0, screen_handles[3], xx, yy);
3905 do_ffc_layer(_screen_draw_buffer, 3, screen_handles[0], xx, yy);
3906 }
3907
3908 do_layer(_screen_draw_buffer, 0, screen_handles[4], xx, yy);
3909 do_ffc_layer(_screen_draw_buffer, 4, screen_handles[0], xx, yy);
3910 do_layer(_screen_draw_buffer, -1, screen_handles[0], xx, yy);
3911 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3912 {
3913 do_layer(_screen_draw_buffer, -1, screen_handles[1], xx, yy);
3914 do_layer(_screen_draw_buffer, -1, screen_handles[2], xx, yy);
3915 }
3916 do_layer(_screen_draw_buffer, 0, screen_handles[5], xx, yy);
3917 do_ffc_layer(_screen_draw_buffer, 5, screen_handles[0], xx, yy);
3918 if(replay_version_check(40))
3919 do_ffc_layer(_screen_draw_buffer, -1, screen_handles[0], xx, yy);
3920 do_layer(_screen_draw_buffer, 0, screen_handles[6], xx, yy);
3921 do_ffc_layer(_screen_draw_buffer, 6, screen_handles[0], xx, yy);
3922 do_ffc_layer(_screen_draw_buffer, 7, screen_handles[0], xx, yy);
3923
3924 blit(_screen_draw_buffer, mappic, 0, 0, x*256, y*176, 256, 176);
3925 }
3926 }
3927
3928 viewport = prev_viewport;
3929 save_bitmap(buf,mappic,RAMpal);
3930 destroy_bitmap(mappic);
3931 destroy_bitmap(_screen_draw_buffer);
3932 return D_O_K;
3933 }
3934
3935 46 void f_Quit(int32_t type)
3936 {
3937
2/4
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 46 times.
✗ Branch 3 not taken.
46 if(type==qQUIT && !Playing)
3938 return;
3939
3940 46 bool from_menu = is_sys_pal;
3941
3942
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if(!from_menu)
3943 {
3944 46 music_pause();
3945 46 pause_all_sfx();
3946 46 sys_mouse();
3947 46 }
3948 46 enter_sys_pal();
3949 46 clear_keybuf();
3950
3951
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 13 times.
46 if (replay_version_check(0, 10))
3952 13 replay_poll();
3953
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if (replay_is_replaying())
3954 46 replay_peek_quit();
3955
3956
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 if (!replay_is_replaying())
3957 switch(type)
3958 {
3959 case qQUIT:
3960 onQuit();
3961 break;
3962
3963 case qRESET:
3964 onReset();
3965 break;
3966
3967 case qEXIT:
3968 onExit();
3969 break;
3970 }
3971
3972
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 if(Quit)
3973 {
3974 46 kill_sfx();
3975 46 music_stop();
3976 46 exit_sys_pal();
3977 46 update_hw_screen();
3978 46 }
3979 else
3980 {
3981 exit_sys_pal();
3982 if(!from_menu)
3983 {
3984 music_resume();
3985 resume_all_sfx();
3986 }
3987 }
3988
3989
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if(!from_menu)
3990 46 game_mouse();
3991 46 eat_buttons();
3992
3993 46 zc_readrawkey(KEY_ESC);
3994
3995 46 zc_readrawkey(KEY_ENTER);
3996 46 }
3997
3998 //----------------------------------------------------------------
3999
4000 int32_t onNoWalls()
4001 {
4002 cheats_enqueue(Cheat::Walls);
4003 return D_O_K;
4004 }
4005
4006 int32_t onIgnoreSideview()
4007 {
4008 cheats_enqueue(Cheat::IgnoreSideView);
4009 return D_O_K;
4010 }
4011
4012 18524436 int32_t input_idle(bool checkmouse)
4013 {
4014 static int32_t mx, my, mz, mb;
4015
4016
4/6
✓ Branch 0 taken 18524436 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4961239 times.
✓ Branch 3 taken 13563197 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4961239 times.
23485675 if(keypressed() || zc_key_pressed() ||
4017
4/8
✓ Branch 0 taken 4961239 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4961239 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4961239 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4961239 times.
✗ Branch 7 not taken.
4961239 (checkmouse && (mx != mouse_x || my != mouse_y || mz != mouse_z || mb != mouse_b)))
4018 {
4019 13563197 idle_count = 0;
4020
4021
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13563197 times.
13563197 if(active_count < MAX_ACTIVE)
4022 {
4023 13563197 ++active_count;
4024 13563197 }
4025 13563197 }
4026
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4961239 times.
4961239 else if(idle_count < MAX_IDLE)
4027 {
4028 4961239 ++idle_count;
4029 4961239 active_count = 0;
4030 4961239 }
4031
4032 18524436 mx = mouse_x;
4033 18524436 my = mouse_y;
4034 18524436 mz = mouse_z;
4035 18524436 mb = mouse_b;
4036
4037 18524436 return idle_count;
4038 }
4039
4040 int32_t onGoFast()
4041 {
4042 cheats_enqueue(Cheat::Fast);
4043 return D_O_K;
4044 }
4045
4046 int32_t onKillCheat()
4047 {
4048 cheats_enqueue(Cheat::Kill);
4049 return D_O_K;
4050 }
4051
4052 int32_t onSecretsCheat()
4053 {
4054 cheats_enqueue(Cheat::TrigSecrets);
4055 return D_O_K;
4056 }
4057 int32_t onSecretsCheatPerm()
4058 {
4059 cheats_enqueue(Cheat::TrigSecretsPerm);
4060 return D_O_K;
4061 }
4062
4063 int32_t onShowLayer0()
4064 {
4065 show_layers[0] = !show_layers[0];
4066 return D_O_K;
4067 }
4068 int32_t onShowLayer1()
4069 {
4070 show_layers[1] = !show_layers[1];
4071 return D_O_K;
4072 }
4073 int32_t onShowLayer2()
4074 {
4075 show_layers[2] = !show_layers[2];
4076 return D_O_K;
4077 }
4078 int32_t onShowLayer3()
4079 {
4080 show_layers[3] = !show_layers[3];
4081 return D_O_K;
4082 }
4083 int32_t onShowLayer4()
4084 {
4085 show_layers[4] = !show_layers[4];
4086 return D_O_K;
4087 }
4088 int32_t onShowLayer5()
4089 {
4090 show_layers[5] = !show_layers[5];
4091 return D_O_K;
4092 }
4093 int32_t onShowLayer6()
4094 {
4095 show_layers[6] = !show_layers[6];
4096 return D_O_K;
4097 }
4098 int32_t onShowLayerO()
4099 {
4100 show_layer_over=!show_layer_over;
4101 return D_O_K;
4102 }
4103 int32_t onShowLayerP()
4104 {
4105 show_layer_push=!show_layer_push;
4106 return D_O_K;
4107 }
4108 int32_t onShowLayerS()
4109 {
4110 show_sprites=!show_sprites;
4111 return D_O_K;
4112 }
4113 int32_t onShowLayerF()
4114 {
4115 show_ffcs=!show_ffcs;
4116 return D_O_K;
4117 }
4118 int32_t onShowLayerW()
4119 {
4120 show_walkflags=!show_walkflags;
4121 if(show_walkflags)
4122 show_effectflags = false;
4123 return D_O_K;
4124 }
4125 int32_t onShowLayerE()
4126 {
4127 show_effectflags=!show_effectflags;
4128 if(show_effectflags)
4129 show_walkflags = false;
4130 return D_O_K;
4131 }
4132 int32_t onShowFFScripts()
4133 {
4134 show_ff_scripts=!show_ff_scripts;
4135 return D_O_K;
4136 }
4137 int32_t onShowHitboxes()
4138 {
4139 show_hitboxes=!show_hitboxes;
4140 return D_O_K;
4141 }
4142 int32_t onShowInfoOpacity()
4143 {
4144 info_opacity = vbound(getnumber("Debug Info Opacity",info_opacity),0,255);
4145 zc_set_config("zc","debug_info_opacity",info_opacity);
4146 return D_O_K;
4147 }
4148
4149 int32_t onLightSwitch()
4150 {
4151 cheats_enqueue(Cheat::Light);
4152 return D_O_K;
4153 }
4154
4155 int32_t onGoTo();
4156 int32_t onGoToComplete();
4157
4158 18524436 bool handle_close_btn_quit()
4159 {
4160
1/2
✓ Branch 0 taken 18524436 times.
✗ Branch 1 not taken.
18524436 if(close_button_quit)
4161 {
4162 close_button_quit=false;
4163 f_Quit(qEXIT);
4164 }
4165 18524436 return (exiting_program = Quit==qEXIT);
4166 }
4167
4168 18524436 void syskeys()
4169 {
4170 18524436 update_system_keys();
4171
4172 int32_t oldtitle_version;
4173
4174 18524436 poll_joystick();
4175
4176 18524436 handle_close_btn_quit();
4177
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18524436 times.
18524436 if(Quit == qEXIT) return;
4178
4179
2/10
✓ Branch 0 taken 18524436 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18524436 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
18524436 if(rMbtn() || (gui_mouse_b() && !mouse_down && ClickToFreeze &&!disableClickToFreeze))
4180 {
4181 System();
4182 }
4183
4184 18524436 mouse_down=gui_mouse_b();
4185
4186
1/2
✓ Branch 0 taken 18524436 times.
✗ Branch 1 not taken.
18524436 if(zc_read_system_key(KEY_F1))
4187 {
4188 if(zc_get_system_key(KEY_ZC_LCONTROL) || zc_get_system_key(KEY_ZC_RCONTROL))
4189 {
4190 halt=!halt;
4191 //zinit.subscreen=(zinit.subscreen+1)%ssdtMAX;
4192 }
4193 else
4194 {
4195 Throttlefps=!Throttlefps;
4196 zc_set_config(cfg_sect,"throttlefps", (int32_t)Throttlefps);
4197 }
4198 }
4199
4200
1/2
✓ Branch 0 taken 18524436 times.
✗ Branch 1 not taken.
18524436 if(zc_read_system_key(KEY_F2))
4201 {
4202 ShowFPS=!ShowFPS;
4203 zc_set_config(cfg_sect,"showfps",(int32_t)ShowFPS);
4204 }
4205
4206
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18524436 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18524436 if(zc_read_system_key(KEY_F3) && Playing) Paused=!Paused;
4207
4208
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18524436 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18524436 if(zc_read_system_key(KEY_F4) && Playing)
4209 {
4210 Paused=true;
4211 Advance=true;
4212 }
4213
4214
1/2
✓ Branch 0 taken 18524436 times.
✗ Branch 1 not taken.
18524436 if(zc_read_system_key(KEY_F6)) onTryQuit();
4215
4216 #ifndef ALLEGRO_MACOSX
4217
1/2
✓ Branch 0 taken 18524436 times.
✗ Branch 1 not taken.
18524436 if(zc_read_system_key(KEY_F9)) f_Quit(qRESET);
4218
4219
1/2
✓ Branch 0 taken 18524436 times.
✗ Branch 1 not taken.
18524436 if(zc_read_system_key(KEY_F10)) f_Quit(qEXIT);
4220 #else
4221 if(zc_read_system_key(KEY_F7)) f_Quit(qRESET);
4222
4223 if(zc_read_system_key(KEY_F8)) f_Quit(qEXIT);
4224 #endif
4225
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 18524436 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
18524436 if(zc_read_system_key(KEY_F5)&&(Playing && cur_screen<128 && DMaps[cur_dmap].flags&dmfVIEWMAP)) onSaveMapPic();
4226
4227
1/2
✓ Branch 0 taken 18524436 times.
✗ Branch 1 not taken.
18524436 if (zc_read_system_key(KEY_F12))
4228 {
4229 onSnapshot();
4230 }
4231
4232
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18524436 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18524436 if(debug_enabled && zc_read_system_key(KEY_TAB))
4233 set_debug(!get_debug());
4234
4235
1/2
✓ Branch 0 taken 18524436 times.
✗ Branch 1 not taken.
18524436 if(CheatModifierKeys())
4236 {
4237 for(Cheat c = (Cheat)1; c < Cheat::Last; c = (Cheat)(c+1))
4238 {
4239 if(!bindable_cheat(c))
4240 continue;
4241 if(get_debug() || cheat >= cheat_lvl(c))
4242 {
4243 if(checkcheat(c))
4244 cheats_hit_bind(c);
4245 }
4246 }
4247 }
4248
4249
1/2
✓ Branch 0 taken 18524436 times.
✗ Branch 1 not taken.
18524436 if(volkeys)
4250 {
4251 if(zc_read_system_key(KEY_PGUP)) master_volume(-1,midi_volume+8);
4252
4253 if(zc_read_system_key(KEY_PGDN)) master_volume(-1,midi_volume==255?248:midi_volume-8);
4254
4255 if(zc_read_system_key(KEY_HOME)) master_volume(digi_volume+8,-1);
4256
4257 if(zc_read_system_key(KEY_END)) master_volume(digi_volume==255?248:digi_volume-8,-1);
4258 }
4259
4260
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 18524436 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
18524436 if(!get_debug() || !SystemKeys || replay_is_replaying())
4261 18524436 goto bottom;
4262
4263 if(zc_readkey(KEY_P)) Paused=!Paused;
4264
4265 if(zc_readkey(KEY_A))
4266 {
4267 Paused=true;
4268 Advance=true;
4269 }
4270
4271 if(zc_readkey(KEY_G)) db=(db==999)?0:999;
4272 #ifndef ALLEGRO_MACOSX
4273 if(zc_readkey(KEY_F8)) Showpal=!Showpal;
4274
4275 if(zc_readkey(KEY_F7))
4276 {
4277 Matrix(ss_speed, ss_density, 0);
4278 game_pal();
4279 }
4280 #else
4281 // The reason these are different on Mac in the first place is that
4282 // the OS doesn't let us use F9 and F10...
4283 if(zc_readkey(KEY_F10)) Showpal=!Showpal;
4284
4285 if(zc_readkey(KEY_F9))
4286 {
4287 Matrix(ss_speed, ss_density, 0);
4288 game_pal();
4289 }
4290 #endif
4291 if(zc_readkey(KEY_PLUS_PAD) || zc_readkey(KEY_EQUALS))
4292 {
4293 //change containers
4294 if(zc_getkey(KEY_ZC_LCONTROL) || zc_getkey(KEY_ZC_RCONTROL))
4295 {
4296 //magic containers
4297 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4298 {
4299 game->set_maxmagic(zc_min(game->get_maxmagic()+game->get_mp_per_block(),game->get_mp_per_block()*8));
4300 }
4301 else
4302 {
4303 game->set_maxlife(zc_min(game->get_maxlife()+game->get_hp_per_heart(),game->get_hp_per_heart()*24));
4304 }
4305 }
4306 else
4307 {
4308 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4309 {
4310 game->set_magic(zc_min(game->get_magic()+1,game->get_maxmagic()));
4311 }
4312 else
4313 {
4314 game->set_life(zc_min(game->get_life()+1,game->get_maxlife()));
4315 }
4316 }
4317 }
4318
4319 if(zc_readkey(KEY_MINUS_PAD) || zc_readkey(KEY_MINUS))
4320 {
4321 //change containers
4322 if(zc_getkey(KEY_ZC_LCONTROL) || zc_getkey(KEY_ZC_RCONTROL))
4323 {
4324 //magic containers
4325 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4326 {
4327 game->set_maxmagic(zc_max(game->get_maxmagic()-game->get_mp_per_block(),0));
4328 game->set_magic(zc_min(game->get_maxmagic(), game->get_magic()));
4329 //heart containers
4330 }
4331 else
4332 {
4333 game->set_maxlife(zc_max(game->get_maxlife()-game->get_hp_per_heart(),game->get_hp_per_heart()));
4334 game->set_life(zc_min(game->get_maxlife(), game->get_life()));
4335 }
4336 }
4337 else
4338 {
4339 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4340 {
4341 game->set_magic(zc_max(game->get_magic()-1,0));
4342 }
4343 else
4344 {
4345 game->set_life(zc_max(game->get_life()-1,0));
4346 }
4347 }
4348 }
4349
4350 if(zc_readkey(KEY_COMMA)) jukebox(currmidi-1);
4351
4352 if(zc_readkey(KEY_STOP)) jukebox(currmidi+1);
4353
4354 verifyBothWeapons();
4355
4356 bottom:
4357
4358
1/2
✓ Branch 0 taken 18524436 times.
✗ Branch 1 not taken.
18524436 if(input_idle(true) > after_time())
4359 {
4360 Matrix(ss_speed, ss_density, 0);
4361 game_pal();
4362 }
4363 18524436 }
4364
4365 1148218 void checkQuitKeys()
4366 {
4367 #ifndef ALLEGRO_MACOSX
4368
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1148218 times.
1148218 if(key[KEY_F9]) f_Quit(qRESET);
4369
4370
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1148218 times.
1148218 if(key[KEY_F10]) f_Quit(qEXIT);
4371 #else
4372 if(key[KEY_F7]) f_Quit(qRESET);
4373
4374 if(key[KEY_F8]) f_Quit(qEXIT);
4375 #endif
4376 1148218 }
4377
4378 18524636 bool CheatModifierKeys()
4379 {
4380 // Cheats are replayed via the X cheat step, no need to check for keyboard input
4381 // to trigger cheats.
4382
2/2
✓ Branch 0 taken 18524336 times.
✓ Branch 1 taken 300 times.
18524636 if (replay_is_replaying())
4383 18524336 return false;
4384
4385
3/4
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 200 times.
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
300 if ( ( cheat_modifier_keys[0] > 0 && key[cheat_modifier_keys[0]] ) ||
4386
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 100 times.
200 ( cheat_modifier_keys[1] > 0 && key[cheat_modifier_keys[1]] ) ||
4387
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
100 (cheat_modifier_keys[0] <= 0 && cheat_modifier_keys[1] <= 0))
4388 {
4389
0/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
200 if ( ( cheat_modifier_keys[2] <= 0 || key[cheat_modifier_keys[2]] ) ||
4390 ( cheat_modifier_keys[3] > 0 && key[cheat_modifier_keys[3]] ) ||
4391 (cheat_modifier_keys[2] <= 0 && cheat_modifier_keys[3] <= 0))
4392 {
4393 return true;
4394 }
4395 }
4396 100 return false;
4397 18524436 }
4398
4399 //99:05:54, for some reason?
4400 #define OLDMAXTIME 21405240
4401 //9000:00:00, the highest even-thousand hour fitting within 32b signed. This is 375 *DAYS*.
4402 #define MAXTIME 1944000000
4403
4404 // (qr, value)
4405 409 static std::queue<std::pair<int, bool>> change_qr_queue;
4406
4407 7 void enqueue_qr_change(int qr, bool value)
4408 {
4409 7 change_qr_queue.push({qr, value});
4410 7 }
4411
4412 // During regular play, QR changes issued through `syskey` / `System` and enqueued
4413 // and soon executed here.
4414 // During playing back a replay file, the replay system adds to the same queue and
4415 // is executed here too.
4416 // This is currently only used to allow users to configure qr_HIDE_BOTTOM_8_PIXELS, but
4417 // could be later extended to all QRs (perhaps as a cheat).
4418 18524857 void process_enqueued_qr_changes()
4419 {
4420
2/2
✓ Branch 0 taken 101 times.
✓ Branch 1 taken 18524756 times.
18524857 if (replay_is_replaying())
4421 18524756 replay_do_qrs();
4422
4423
2/2
✓ Branch 0 taken 18524857 times.
✓ Branch 1 taken 7 times.
18524864 while (!change_qr_queue.empty())
4424 {
4425 28 auto [qr, value] = change_qr_queue.front();
4426 7 change_qr_queue.pop();
4427
4428 // Don't modify `quest_rules`, as that is used to store the canonical QR value which can be reset to
4429 // via system menus. Changing the unpacked array is enough to modify the engine's behavior.
4430 14 _qrs_unpacked[qr] = value;
4431 7 apply_qr_rule(qr);
4432
4433
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
7 if (replay_is_recording())
4434 2 replay_step_qr(qr, value);
4435 }
4436 18524857 }
4437
4438 18525823 void advanceframe(bool allowwavy, bool sfxcleanup, bool allowF6Script)
4439 {
4440
1/2
✓ Branch 0 taken 18525823 times.
✗ Branch 1 not taken.
18525823 if(zcmusic!=NULL)
4441 {
4442 zcmusic_poll();
4443 }
4444 18525823 zcmixer_update(zcmixer, emusic_volume, FFCore.usr_music_volume, get_qr(qr_OLD_SCRIPT_VOLUME));
4445
4446 18525823 updatescr(allowwavy);
4447
4448 18525823 Advance=false;
4449
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 18525823 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 18525823 times.
18525823 while(Paused && !Advance && !Quit)
4450 {
4451 // have to call this, otherwise we'll get an infinite loop
4452 syskeys();
4453 if(allowF6Script)
4454 {
4455 FFCore.runF6Engine();
4456 }
4457
4458 #ifdef _WIN32
4459
4460 if(use_dwm_flush)
4461 {
4462 do_DwmFlush();
4463 }
4464
4465 #endif
4466
4467 // to keep music playing
4468 if(zcmusic!=NULL)
4469 {
4470 zcmusic_poll();
4471 }
4472
4473 update_hw_screen();
4474 }
4475
4476
2/2
✓ Branch 0 taken 18524473 times.
✓ Branch 1 taken 1350 times.
18525823 if(Quit)
4477 1350 return;
4478
4479
3/4
✓ Branch 0 taken 18009022 times.
✓ Branch 1 taken 515451 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18009022 times.
18524473 if(Playing && game->get_time()<unsigned(get_qr(qr_GREATER_MAX_TIME) ? MAXTIME : OLDMAXTIME))
4480 18009022 game->change_time(1);
4481
4482 // Many mistakes have been make re: inputs, and we are stuck with many replays relying on those mistakes.
4483
4484 18524473 bool should_reset_down_state = !get_qr(qr_BROKEN_INPUT_DOWN_STATE);
4485
2/2
✓ Branch 0 taken 8724858 times.
✓ Branch 1 taken 9799615 times.
18524473 if (replay_version_check(0, 16))
4486 9799615 should_reset_down_state = replay_version_check(11, 16);
4487
2/2
✓ Branch 0 taken 15093285 times.
✓ Branch 1 taken 3431188 times.
18524473 if (should_reset_down_state)
4488 {
4489
2/2
✓ Branch 0 taken 61761384 times.
✓ Branch 1 taken 3431188 times.
65192572 for (int i = 0; i < ZC_CONTROL_STATES; i++)
4490 61761384 down_control_states[i] = raw_control_state[i];
4491 3431188 }
4492
4493
2/2
✓ Branch 0 taken 37 times.
✓ Branch 1 taken 18524436 times.
18524473 if (replay_is_active())
4494 {
4495
2/2
✓ Branch 0 taken 1545420 times.
✓ Branch 1 taken 16979016 times.
18524436 if (replay_version_check(3))
4496 16979016 replay_poll();
4497
4498
4/4
✓ Branch 0 taken 7478911 times.
✓ Branch 1 taken 11045525 times.
✓ Branch 2 taken 100535 times.
✓ Branch 3 taken 7378376 times.
18524436 if (replay_version_check(11) || replay_version_check(6, 8))
4499 11146060 replay_peek_input();
4500 18524436 }
4501
4502 18524473 process_enqueued_qr_changes();
4503
4504 18524473 load_control_called_this_frame = false;
4505
4506 18524473 poll_keyboard();
4507 18524473 update_keys();
4508
4509 18524473 ++frame;
4510
4511
2/2
✓ Branch 0 taken 137 times.
✓ Branch 1 taken 18524336 times.
18524473 if (replay_is_replaying())
4512 18524336 replay_do_cheats();
4513 18524473 syskeys();
4514
4515 // The mouse variables can change from the mouse thread at anytime during a frame,
4516 // so save the result at the start so that replaying is consistent.
4517 18524473 script_mouse_x = gui_mouse_x();
4518 18524473 script_mouse_y = gui_mouse_y();
4519 18524473 script_mouse_z = mouse_z;
4520 18524473 script_mouse_b = mouse_b;
4521
4522 // Cheats used via the System menu (called by syskeys) will call cheats_enqueue. syskeys
4523 // is called just above, and in the paused loop above, so the queue-and-defer-slightly
4524 // approach here means it doesn't matter which call adds the cheat.
4525 18524473 cheats_execute_queued();
4526
4527
2/2
✓ Branch 0 taken 137 times.
✓ Branch 1 taken 18524336 times.
18524473 if (replay_is_replaying())
4528 18524336 replay_peek_quit();
4529
2/2
✓ Branch 0 taken 18524427 times.
✓ Branch 1 taken 46 times.
18524473 if (GameFlags & GAMEFLAG_TRYQUIT)
4530 46 replay_step_quit(0);
4531
2/2
✓ Branch 0 taken 3322 times.
✓ Branch 1 taken 18521151 times.
18524473 if(allowF6Script)
4532 18521151 FFCore.runF6Engine();
4533
2/2
✓ Branch 0 taken 754 times.
✓ Branch 1 taken 18523719 times.
18524473 if (Quit)
4534 754 replay_step_quit(Quit);
4535
4536 #ifdef _WIN32
4537
4538 if(use_dwm_flush)
4539 {
4540 do_DwmFlush();
4541 }
4542
4543 #endif
4544
4545
2/2
✓ Branch 0 taken 208645 times.
✓ Branch 1 taken 18315828 times.
18524473 if(sfxcleanup)
4546 18315828 sfx_cleanup();
4547
4548 18524473 jit_poll();
4549
4550 #ifdef __EMSCRIPTEN__
4551 // Yield the main thread back to the browser occasionally.
4552 if (is_headless())
4553 {
4554 static int rate = 10000;
4555 static int force_yield = rate;
4556 if (force_yield++ >= rate)
4557 {
4558 force_yield = 0;
4559 emscripten_sleep(0);
4560 }
4561 }
4562 #endif
4563
4564
3/4
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 18524373 times.
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
18524473 if (zqtesting_mode && test_mode_auto_restart)
4565 {
4566 static auto last_write_time = fs::last_write_time(qstpath);
4567 static auto last_check = std::chrono::system_clock::now();
4568
4569 if (std::chrono::system_clock::now() - last_check > 200ms)
4570 {
4571 last_check = std::chrono::system_clock::now();
4572 auto write_time = fs::last_write_time(qstpath);
4573 if (last_write_time != write_time)
4574 {
4575 last_write_time = write_time;
4576 disableClickToFreeze = false;
4577 Quit = qRESET;
4578 replay_quit();
4579 }
4580 }
4581 }
4582 18525823 }
4583
4584 590 void zapout()
4585 {
4586 590 set_clip_rect(scrollbuf_old, 0, 0, scrollbuf_old->w, scrollbuf_old->h);
4587 590 blit(framebuf,scrollbuf_old,0,0,256,0,256,framebuf->h);
4588
4589 590 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4590 590 script_drawing_commands.Clear();
4591
4592 // zap out
4593
2/2
✓ Branch 0 taken 590 times.
✓ Branch 1 taken 14160 times.
14750 for(int32_t i=1; i<=24; i++)
4594 {
4595 14160 draw_fuzzy(i);
4596 14160 advanceframe(true);
4597
4598
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14160 times.
14160 if(Quit)
4599 {
4600 break;
4601 }
4602 14160 }
4603 590 }
4604
4605 588 void zapin()
4606 {
4607 588 FFCore.warpScriptCheck();
4608 588 draw_screen();
4609 588 set_clip_rect(scrollbuf_old, 0, 0, scrollbuf_old->w, scrollbuf_old->h);
4610 588 blit(framebuf,scrollbuf_old,0,0,256,0,256,framebuf->h);
4611
4612 // zap out
4613 588 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4614
2/2
✓ Branch 0 taken 588 times.
✓ Branch 1 taken 14112 times.
14700 for(int32_t i=24; i>=1; i--)
4615 {
4616 14112 draw_fuzzy(i);
4617 14112 advanceframe(true);
4618
4619
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14112 times.
14112 if(Quit)
4620 {
4621 break;
4622 }
4623 14112 }
4624 588 }
4625
4626
4627 235 void wavyout(bool showhero)
4628 {
4629 235 draw_screen(showhero);
4630
4631 235 BITMAP *wavebuf = create_bitmap_ex(8,288,framebuf->h);
4632 235 clear_to_color(wavebuf,0);
4633 235 blit(framebuf,wavebuf,0,0,16,0,framebuf->w,framebuf->h);
4634
4635 static PALETTE wavepal;
4636
4637 int32_t ofs;
4638 235 int32_t amplitude=8;
4639
4640 235 int32_t wavelength=4;
4641 235 int height = viewport.visible_height(show_bottom_8px);
4642 235 double palpos=0, palstep=4, palstop=126;
4643
4644 235 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4645
2/2
✓ Branch 0 taken 234 times.
✓ Branch 1 taken 9845 times.
10079 for(int32_t i=0; i<height; i+=wavelength)
4646 {
4647
2/2
✓ Branch 0 taken 2520320 times.
✓ Branch 1 taken 9845 times.
2530165 for(int32_t l=0; l<256; l++)
4648 {
4649 2520320 wavepal[l].r=vbound(int32_t(RAMpal[l].r+((palpos/palstop)*(255-RAMpal[l].r))),0,255);
4650 2520320 wavepal[l].g=vbound(int32_t(RAMpal[l].g+((palpos/palstop)*(255-RAMpal[l].g))),0,255);
4651 2520320 wavepal[l].b=vbound(int32_t(RAMpal[l].b+((palpos/palstop)*(255-RAMpal[l].b))),0,255);
4652 2520320 }
4653
4654 9845 palpos+=palstep;
4655
4656
1/2
✓ Branch 0 taken 9845 times.
✗ Branch 1 not taken.
9845 if(palpos>=0)
4657 {
4658 9845 hw_palette = &wavepal;
4659 9845 update_hw_pal = true;
4660 9845 }
4661 else
4662 {
4663 hw_palette = &RAMpal;
4664 update_hw_pal = true;
4665 }
4666
4667
2/2
✓ Branch 0 taken 1653960 times.
✓ Branch 1 taken 9845 times.
1663805 for(int32_t j=0; j+playing_field_offset<framebuf->h; j++)
4668 {
4669
2/2
✓ Branch 0 taken 423413760 times.
✓ Branch 1 taken 1653960 times.
425067720 for(int32_t k=0; k<256; k++)
4670 {
4671 423413760 ofs=0;
4672
4673
4/4
✓ Branch 0 taken 206448640 times.
✓ Branch 1 taken 216965120 times.
✓ Branch 2 taken 103224320 times.
✓ Branch 3 taken 103224320 times.
423413760 if((j<i)&&(j&1))
4674 {
4675 103224320 ofs=int32_t(zc::math::Sin((double(i+j)*2*PI/height))*amplitude);
4676 103224320 }
4677
4678 423413760 framebuf->line[j+playing_field_offset][k]=wavebuf->line[j+playing_field_offset][k+ofs+16];
4679 423413760 }
4680 1653960 }
4681
4682 9845 advanceframe(true);
4683
4684
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9844 times.
9845 if(Quit)
4685 1 break;
4686 9844 }
4687
4688 235 destroy_bitmap(wavebuf);
4689
4690 235 hw_palette = &RAMpal;
4691 235 update_hw_pal = true;
4692 235 }
4693
4694 232 void wavyin()
4695 {
4696 232 draw_screen();
4697
4698 232 BITMAP *wavebuf = create_bitmap_ex(8,288,framebuf->h);
4699 232 clear_to_color(wavebuf,0);
4700 232 blit(framebuf,wavebuf,0,0,16,0,framebuf->w,framebuf->h);
4701
4702 static PALETTE wavepal;
4703
4704 232 refreshpal=false;
4705 int32_t ofs;
4706 232 int32_t amplitude=8;
4707 232 int32_t wavelength=4;
4708 232 int height = viewport.visible_height(show_bottom_8px);
4709 232 double palpos=height, palstep=4, palstop=126;
4710
4711 232 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4712
2/2
✓ Branch 0 taken 231 times.
✓ Branch 1 taken 9703 times.
9934 for(int32_t i=0; i<height; i+=wavelength)
4713 {
4714
2/2
✓ Branch 0 taken 2483968 times.
✓ Branch 1 taken 9703 times.
2493671 for(int32_t l=0; l<256; l++)
4715 {
4716 2483968 wavepal[l].r=vbound(int32_t(RAMpal[l].r+((palpos/palstop)*(255-RAMpal[l].r))),0,255);
4717 2483968 wavepal[l].g=vbound(int32_t(RAMpal[l].g+((palpos/palstop)*(255-RAMpal[l].g))),0,255);
4718 2483968 wavepal[l].b=vbound(int32_t(RAMpal[l].b+((palpos/palstop)*(255-RAMpal[l].b))),0,255);
4719 2483968 }
4720
4721 9703 palpos-=palstep;
4722
4723
1/2
✓ Branch 0 taken 9703 times.
✗ Branch 1 not taken.
9703 if(palpos>=0)
4724 {
4725 9703 hw_palette = &wavepal;
4726 9703 update_hw_pal = true;
4727 9703 }
4728 else
4729 {
4730 hw_palette = &RAMpal;
4731 update_hw_pal = true;
4732 }
4733
4734
2/2
✓ Branch 0 taken 1630104 times.
✓ Branch 1 taken 9703 times.
1639807 for(int32_t j=0; j+playing_field_offset<framebuf->h; j++)
4735 {
4736
2/2
✓ Branch 0 taken 417306624 times.
✓ Branch 1 taken 1630104 times.
418936728 for(int32_t k=0; k<256; k++)
4737 {
4738 417306624 ofs=0;
4739
4740
4/4
✓ Branch 0 taken 211158272 times.
✓ Branch 1 taken 206148352 times.
✓ Branch 2 taken 106821120 times.
✓ Branch 3 taken 104337152 times.
417306624 if((j<(height-1-i))&&(j&1))
4741 {
4742 104337152 ofs=int32_t(zc::math::Sin((double(i+j)*2*PI/height))*amplitude);
4743 104337152 }
4744
4745 417306624 framebuf->line[j+playing_field_offset][k]=wavebuf->line[j+playing_field_offset][k+ofs+16];
4746 417306624 }
4747 1630104 }
4748
4749 9703 advanceframe(true);
4750
4751
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9702 times.
9703 if(Quit)
4752 1 break;
4753 9702 }
4754
4755 232 destroy_bitmap(wavebuf);
4756
4757 232 hw_palette = &RAMpal;
4758 232 update_hw_pal = true;
4759 232 }
4760
4761 4348 void blackscr(int32_t fcnt,bool showsubscr)
4762 {
4763 4348 reset_pal_cycling();
4764 4348 script_drawing_commands.Clear();
4765
4766 4348 FFCore.warpScriptCheck();
4767 4348 bool showtime = game->should_show_time();
4768
2/2
✓ Branch 0 taken 4341 times.
✓ Branch 1 taken 129997 times.
134338 while(fcnt>0)
4769 {
4770 129997 clear_bitmap(framebuf);
4771
4772
2/2
✓ Branch 0 taken 59310 times.
✓ Branch 1 taken 70687 times.
129997 if(showsubscr)
4773 {
4774 70687 put_passive_subscr(framebuf,0,0,showtime,sspUP);
4775
3/4
✓ Branch 0 taken 70687 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1470 times.
✓ Branch 3 taken 69217 times.
70687 if(get_qr(qr_SCRIPTDRAWSINWARPS) || (get_qr(qr_PASSIVE_SUBSCRIPT_RUNS_WHEN_GAME_IS_FROZEN)))
4776 {
4777 1470 do_script_draws(framebuf, origin_scr, 0, playing_field_offset);
4778 1470 }
4779 70687 }
4780
4781 129997 advanceframe(true);
4782
4783
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 129990 times.
129997 if(Quit)
4784 7 break;
4785
4786 129990 --fcnt;
4787 }
4788 4348 }
4789
4790 2736 void openscreen(int32_t shape)
4791 {
4792 2736 update_viewport();
4793 2736 is_opening_screen = true;
4794 2736 reset_pal_cycling();
4795 2736 black_opening_count=0;
4796
4797
3/4
✓ Branch 0 taken 530 times.
✓ Branch 1 taken 2206 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 530 times.
2736 if(COOLSCROLL || shape>-1)
4798 {
4799 2206 open_black_opening(HeroX()+8, (HeroY()-HeroZ()-HeroFakeZ())+8+playing_field_offset, true, shape);
4800 2206 return;
4801 }
4802 else
4803 {
4804 530 Hero.setDontDraw(true);
4805 530 show_subscreen_dmap_dots=false;
4806 530 show_subscreen_numbers=false;
4807 530 show_subscreen_life=false;
4808 }
4809
4810 530 int32_t x=128;
4811
4812 530 FFCore.warpScriptCheck();
4813
2/2
✓ Branch 0 taken 530 times.
✓ Branch 1 taken 42400 times.
42930 for(int32_t i=0; i<80; i++)
4814 {
4815 42400 draw_screen();
4816 42400 x=128-(((i*128/80)/8)*8);
4817
4818
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42400 times.
42400 if(x>0)
4819 {
4820 42400 rectfill(framebuf,0,playing_field_offset,x,(viewport.h - 1)+playing_field_offset,0);
4821 42400 rectfill(framebuf,viewport.w-x,playing_field_offset,255,(viewport.h - 1)+playing_field_offset,0);
4822 42400 }
4823
4824 42400 advanceframe(true);
4825
4826
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42400 times.
42400 if(Quit)
4827 {
4828 break;
4829 }
4830 42400 }
4831
4832 530 Hero.setDontDraw(false);
4833 530 show_subscreen_items=true;
4834 530 show_subscreen_dmap_dots=true;
4835 530 show_subscreen_numbers=true;
4836 530 show_subscreen_life=true;
4837 2736 }
4838
4839 14 void closescreen(int32_t shape)
4840 {
4841 14 is_opening_screen = false;
4842 14 reset_pal_cycling();
4843 14 black_opening_count=0;
4844
4845
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
14 if(COOLSCROLL || shape>-1)
4846 {
4847 14 close_black_opening(HeroX()+8, (HeroY()-HeroZ()-HeroFakeZ())+8+playing_field_offset, true, shape);
4848 14 return;
4849 }
4850 else
4851 {
4852 Hero.setDontDraw(true);
4853 show_subscreen_dmap_dots=false;
4854 show_subscreen_numbers=false;
4855 // show_subscreen_items=false;
4856 show_subscreen_life=false;
4857 }
4858
4859 int32_t x=128;
4860
4861 FFCore.warpScriptCheck();
4862 for(int32_t i=79; i>=0; --i)
4863 {
4864 draw_screen();
4865 x=128-(((i*128/80)/8)*8);
4866
4867 if(x>0)
4868 {
4869 rectfill(framebuf,0,playing_field_offset,x,(viewport.h - 1)+playing_field_offset,0);
4870 rectfill(framebuf,viewport.w-x,playing_field_offset,255,(viewport.h - 1)+playing_field_offset,0);
4871 }
4872
4873 advanceframe(true);
4874
4875 if(Quit)
4876 {
4877 break;
4878 }
4879 }
4880
4881 Hero.setDontDraw(false);
4882 show_subscreen_items=true;
4883 show_subscreen_dmap_dots=true;
4884 14 }
4885
4886 324 int32_t TriforceCount()
4887 {
4888 324 int32_t c=0;
4889
4890
2/2
✓ Branch 0 taken 2592 times.
✓ Branch 1 taken 324 times.
2916 for(int32_t i=1; i<=8; i++)
4891
2/2
✓ Branch 0 taken 484 times.
✓ Branch 1 taken 2108 times.
4700 if(game->lvlitems[i]&liTRIFORCE)
4892 2108 ++c;
4893
4894 324 return c;
4895 }
4896
4897 int32_t onCustomGame()
4898 {
4899 auto save = get_unset_save_slot();
4900 if (!save)
4901 return D_CLOSE;
4902
4903 if (prompt_for_quest_path(save->header->qstpath))
4904 {
4905 save->header->qstpath = qstpath;
4906 return D_O_K;
4907 }
4908
4909 return D_CLOSE;
4910 }
4911
4912 int32_t onContinue()
4913 {
4914 return D_CLOSE;
4915 }
4916
4917 int32_t onThrottleFPS()
4918 {
4919 Throttlefps = !Throttlefps;
4920 zc_set_config(cfg_sect,"throttlefps", (int32_t)Throttlefps);
4921 return D_O_K;
4922 }
4923
4924 int32_t onWinPosSave()
4925 {
4926 SaveWinPos = !SaveWinPos;
4927 zc_set_config(cfg_sect,"save_window_position",(int32_t)SaveWinPos);
4928 return D_O_K;
4929 }
4930 int32_t onIntegerScaling()
4931 {
4932 scaleForceInteger = !scaleForceInteger;
4933 zc_set_config("zeldadx","scaling_force_integer",(int)scaleForceInteger);
4934 return D_O_K;
4935 }
4936 int32_t onStretchGame()
4937 {
4938 stretchGame = !stretchGame;
4939 zc_set_config("zeldadx","stretch_game_area",stretchGame?1:0);
4940 return D_O_K;
4941 }
4942
4943 int32_t onClickToFreeze()
4944 {
4945 ClickToFreeze = !ClickToFreeze;
4946 zc_set_config(cfg_sect,"clicktofreeze", (int32_t)ClickToFreeze);
4947 return D_O_K;
4948 }
4949
4950 int32_t OnSaveZCConfig()
4951 {
4952 if(jwin_alert3(
4953 "Save Configuration",
4954 "Are you sure that you wish to save your present configuration settings?",
4955 "This will overwrite your prior settings!",
4956 NULL,
4957 "&Yes",
4958 "&No",
4959 NULL,
4960 'y',
4961 'n',
4962 0,
4963 get_zc_font(font_lfont)) == 1)
4964 {
4965 save_game_configs();
4966 return D_O_K;
4967 }
4968 else return D_O_K;
4969 }
4970
4971 int32_t OnnClearQuestDir()
4972 {
4973 auto current_path = fs::current_path() / "quests";
4974 if(jwin_alert3(
4975 "Clear Current Directory Cache",
4976 "Are you sure that you wish to reset where ZC Player looks for quests?",
4977 fmt::format("The new directory will be: {}", current_path.string()).c_str(),
4978 NULL,
4979 "&Yes",
4980 "&No",
4981 NULL,
4982 'y',
4983 'n',
4984 0,
4985 get_zc_font(font_lfont)) == 1)
4986 {
4987 zc_set_config("zeldadx","quest_dir","quests");
4988 flush_config_file();
4989 strcpy(qstdir,"quests");
4990 #ifdef __EMSCRIPTEN__
4991 em_sync_fs();
4992 #endif
4993 return D_O_K;
4994 }
4995 else return D_O_K;
4996 }
4997
4998 int32_t onConsole()
4999 {
5000 if ( !console_enabled )
5001 {
5002 AlertDialog("ZC Console",
5003 "Open the ZC Console?"
5004 "\nThis will display any messages logged by scripts,"
5005 " including errors.",
5006 [&](bool ret,bool)
5007 {
5008 if(ret)
5009 {
5010 FFCore.ZScriptConsole(true);
5011 }
5012 }).show();
5013 return D_O_K;
5014 }
5015 else
5016 {
5017 FFCore.ZScriptConsole(false);
5018 return D_O_K;
5019 }
5020 }
5021
5022 int32_t onClrConsoleOnReload()
5023 {
5024 clearConsoleOnReload = !clearConsoleOnReload;
5025 zc_set_config("CONSOLE","clear_console_on_reload",clearConsoleOnReload?1:0);
5026 return D_O_K;
5027 }
5028 int32_t onClrConsoleOnLoad()
5029 {
5030 clearConsoleOnLoad = !clearConsoleOnLoad;
5031 zc_set_config("CONSOLE","clear_console_on_load",clearConsoleOnLoad?1:0);
5032 return D_O_K;
5033 }
5034
5035
5036 int32_t onFrameSkip()
5037 {
5038 FrameSkip = !FrameSkip;
5039 return D_O_K;
5040 }
5041
5042 int32_t onSaveDragResize()
5043 {
5044 SaveDragResize = !SaveDragResize;
5045 zc_set_config(cfg_sect,"save_drag_resize",(int32_t)SaveDragResize);
5046 return D_O_K;
5047 }
5048
5049 int32_t onDragAspect()
5050 {
5051 DragAspect = !DragAspect;
5052 zc_set_config(cfg_sect,"drag_aspect",(int32_t)DragAspect);
5053 return D_O_K;
5054 }
5055
5056 int32_t onTransLayers()
5057 {
5058 TransLayers = !TransLayers;
5059 zc_set_config(cfg_sect,"translayers",(int32_t)TransLayers);
5060 return D_O_K;
5061 }
5062
5063 int32_t onNESquit()
5064 {
5065 NESquit = !NESquit;
5066 zc_set_config(cfg_sect,"fastquit",(int32_t)NESquit);
5067 return D_O_K;
5068 }
5069
5070 int32_t onVolKeys()
5071 {
5072 volkeys = !volkeys;
5073 zc_set_config(sfx_sect,"volkeys",(int32_t)volkeys);
5074 return D_O_K;
5075 }
5076
5077 int32_t onShowFPS()
5078 {
5079 ShowFPS = !ShowFPS;
5080 zc_set_config(cfg_sect,"showfps",(int32_t)ShowFPS);
5081 return D_O_K;
5082 }
5083
5084 int32_t onShowTime()
5085 {
5086 ShowGameTime = !ShowGameTime;
5087 zc_set_config(cfg_sect,"showtime",ShowGameTime);
5088 return D_O_K;
5089 }
5090
5091 2185883448 bool is_Fkey(int32_t k)
5092 {
5093
2/2
✓ Branch 0 taken 222293232 times.
✓ Branch 1 taken 1963590216 times.
2185883448 switch(k)
5094 {
5095 case KEY_F1:
5096 case KEY_F2:
5097 case KEY_F3:
5098 case KEY_F4:
5099 case KEY_F5:
5100 case KEY_F6:
5101 case KEY_F7:
5102 case KEY_F8:
5103 case KEY_F9:
5104 case KEY_F10:
5105 case KEY_F11:
5106 case KEY_F12:
5107 222293232 return true;
5108 }
5109
5110 1963590216 return false;
5111 2185883448 }
5112
5113 void kb_getkey(DIALOG *d);
5114
5115 //Used by all keyboard key settings dialogues.
5116 void kb_clearjoystick(DIALOG *d)
5117 {
5118 d->flags|=D_SELECTED;
5119
5120 jwin_button_proc(MSG_DRAW,d,0);
5121 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5122 // text_mode(vc(11));
5123 textout_centre_ex(screen, font, "Press any key to clear", gui_bmp->w/2, gui_bmp->h/2 - 8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5124 textout_centre_ex(screen, font, "ESC to cancel", gui_bmp->w/2, gui_bmp->h/2, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5125
5126 update_hw_screen();
5127
5128 clear_keybuf();
5129 int32_t k = next_press_key();
5130 clear_keybuf();
5131
5132 //shnarf
5133 //47=f1
5134 //59=esc
5135 // if(k>0 && k<123 && !((k>46)&&(k<60)))
5136 // *((int32_t*)d->dp3) = k;
5137 if ( k != 59 ) *((int32_t*)d->dp3) = 0;
5138
5139
5140 d->flags&=~D_SELECTED;
5141 }
5142
5143 //Clears key to 0.
5144 //Used by all keyboard key settings dialogues.
5145 void kb_clearkey(DIALOG *d);
5146
5147 int32_t d_j_clearbutton_proc(int32_t msg,DIALOG *d,int32_t c)
5148 {
5149 switch(msg)
5150 {
5151 case MSG_KEY:
5152 case MSG_CLICK:
5153
5154 kb_clearjoystick(d);
5155
5156 while(gui_mouse_b())
5157 {
5158 clear_keybuf();
5159 rest(1);
5160 }
5161
5162 return D_REDRAW;
5163 }
5164
5165 return jwin_button_proc(msg,d,c);
5166 }
5167
5168 int32_t d_kbutton_proc(int32_t msg,DIALOG *d,int32_t c);
5169 //Only used in keyboard settings dialogues to clear keys.
5170 int32_t d_k_clearbutton_proc(int32_t msg,DIALOG *d,int32_t c);
5171
5172 int32_t j_getbtn(DIALOG *d)
5173 {
5174 d->flags|=D_SELECTED;
5175 jwin_button_proc(MSG_DRAW,d,0);
5176 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5177 // text_mode(vc(11));
5178 int32_t y = screen->h/2 - 12;
5179 textout_centre_ex(screen, font, "Press a button", screen->w/2, y, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5180 textout_centre_ex(screen, font, "ESC to cancel", screen->w/2, y+8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5181 textout_centre_ex(screen, font, "SPACE to disable", screen->w/2, y+16, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5182
5183 update_hw_screen();
5184
5185 int32_t b = next_joy_input(true);
5186 if (b == -2)
5187 return D_CLOSE;
5188
5189 if(b>=0)
5190 *((int32_t*)d->dp3) = b;
5191
5192 d->flags&=~D_SELECTED;
5193
5194 return D_O_K;
5195 }
5196
5197 void j_getstick(DIALOG *d)
5198 {
5199 d->flags|=D_SELECTED;
5200 jwin_button_proc(MSG_DRAW,d,0);
5201 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5202 // text_mode(vc(11));
5203 int32_t y = screen->h/2 - 12;
5204 textout_centre_ex(screen, font, "Move a stick (or DPAD)", screen->w/2, y, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5205 textout_centre_ex(screen, font, "ESC to cancel", screen->w/2, y+8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5206 textout_centre_ex(screen, font, "SPACE to disable", screen->w/2, y+16, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5207
5208 update_hw_screen();
5209
5210 int32_t b = next_joy_input(false);
5211
5212 if(b>=0)
5213 *((int32_t*)d->dp3) = b;
5214
5215 d->flags&=~D_SELECTED;
5216 }
5217
5218 int32_t d_jbutton_proc(int32_t msg,DIALOG *d,int32_t c)
5219 {
5220 switch(msg)
5221 {
5222 case MSG_KEY:
5223 case MSG_CLICK:
5224
5225 int ret = j_getbtn(d);
5226 if (ret != D_O_K)
5227 return ret;
5228
5229 while(gui_mouse_b()) {
5230 rest(1);
5231 clear_keybuf();
5232 }
5233
5234 return D_REDRAW;
5235 }
5236
5237 return jwin_button_proc(msg,d,c);
5238 }
5239
5240 int32_t d_jstick_proc(int32_t msg,DIALOG *d,int32_t c)
5241 {
5242 switch(msg)
5243 {
5244 case MSG_KEY:
5245 case MSG_CLICK:
5246
5247 j_getstick(d);
5248
5249 while(gui_mouse_b()) {
5250 rest(1);
5251 clear_keybuf();
5252 }
5253
5254 return D_REDRAW;
5255 }
5256
5257 return jwin_button_proc(msg,d,c);
5258 }
5259
5260 //shnarf
5261 extern const char *key_str[];
5262 std::string get_keystr(int key);
5263
5264 const char *pan_str[4] = { " MONO", " 1/2", " 3/4", " FULL" };
5265
5266 static char str_a[80],str_b[80],str_s[80],str_m[80],str_l[80],str_r[80],str_p[80],str_ex1[80],str_ex2[80],str_ex3[80],str_ex4[80],
5267 str_leftmod1[80],str_leftmod2[80],str_rightmod1[80],str_rightmod2[80], str_left[80], str_right[80], str_up[80], str_down[80],
5268 str_primary_stick[80], str_secondary_stick[80];
5269
5270 int32_t d_stringloader(int32_t msg,DIALOG *d,int32_t c)
5271 {
5272 //these are here to bypass compiler warnings about unused arguments
5273 c=c;
5274
5275 if (d->w == 1)
5276 {
5277 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
5278 {
5279 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
5280 return D_CLOSE;
5281 }
5282 }
5283
5284 if(msg==MSG_DRAW)
5285 {
5286 switch(d->w)
5287 {
5288 case 0:
5289 sprintf(str_a,"%03d\n%s",Akey,key_str[Akey]);
5290 sprintf(str_b,"%03d\n%s",Bkey,key_str[Bkey]);
5291 sprintf(str_s,"%03d\n%s",Skey,key_str[Skey]);
5292 sprintf(str_l,"%03d\n%s",Lkey,key_str[Lkey]);
5293 sprintf(str_r,"%03d\n%s",Rkey,key_str[Rkey]);
5294 sprintf(str_p,"%03d\n%s",Pkey,key_str[Pkey]);
5295 sprintf(str_ex1,"%03d\n%s",Exkey1,key_str[Exkey1]);
5296 sprintf(str_ex2,"%03d\n%s",Exkey2,key_str[Exkey2]);
5297 sprintf(str_ex3,"%03d\n%s",Exkey3,key_str[Exkey3]);
5298 sprintf(str_ex4,"%03d\n%s",Exkey4,key_str[Exkey4]);
5299 sprintf(str_up,"%03d\n%s",DUkey,key_str[DUkey]);
5300 sprintf(str_down,"%03d\n%s",DDkey,key_str[DDkey]);
5301 sprintf(str_left,"%03d\n%s",DLkey,key_str[DLkey]);
5302 sprintf(str_right,"%03d\n%s",DRkey,key_str[DRkey]);
5303 sprintf(str_leftmod1,"%03d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5304 sprintf(str_leftmod2,"%03d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5305 sprintf(str_rightmod1,"%03d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5306 sprintf(str_rightmod2,"%03d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5307 break;
5308
5309 case 1:
5310 sprintf(str_a,"%03d\n%s",Abtn,joybtn_name(Abtn));
5311 sprintf(str_b,"%03d\n%s",Bbtn,joybtn_name(Bbtn));
5312 sprintf(str_s,"%03d\n%s",Sbtn,joybtn_name(Sbtn));
5313 sprintf(str_l,"%03d\n%s",Lbtn,joybtn_name(Lbtn));
5314 sprintf(str_r,"%03d\n%s",Rbtn,joybtn_name(Rbtn));
5315 sprintf(str_m,"%03d\n%s",Mbtn,joybtn_name(Mbtn));
5316 sprintf(str_p,"%03d\n%s",Pbtn,joybtn_name(Pbtn));
5317 sprintf(str_ex1,"%03d\n%s",Exbtn1,joybtn_name(Exbtn1));
5318 sprintf(str_ex2,"%03d\n%s",Exbtn2,joybtn_name(Exbtn2));
5319 sprintf(str_ex3,"%03d\n%s",Exbtn3,joybtn_name(Exbtn3));
5320 sprintf(str_ex4,"%03d\n%s",Exbtn4,joybtn_name(Exbtn4));
5321 sprintf(str_up,"%03d\n%s",DUbtn,joybtn_name(DUbtn));
5322 sprintf(str_down,"%03d\n%s",DDbtn,joybtn_name(DDbtn));
5323 sprintf(str_left,"%03d\n%s",DLbtn,joybtn_name(DLbtn));
5324 sprintf(str_right,"%03d\n%s",DRbtn,joybtn_name(DRbtn));
5325 sprintf(str_primary_stick,"%03d\n%s",js_stick_1_x_stick,joystick_name(js_stick_1_x_stick));
5326 sprintf(str_secondary_stick,"%03d\n%s",js_stick_2_x_stick,joystick_name(js_stick_2_x_stick));
5327 sprintf(str_leftmod1,"%03d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5328 sprintf(str_leftmod2,"%03d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5329 sprintf(str_rightmod1,"%03d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5330 sprintf(str_rightmod2,"%03d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5331 break;
5332
5333 case 2:
5334 sprintf(str_a," %3d",midi_volume);
5335 sprintf(str_l," %3d",emusic_volume);
5336 sprintf(str_r," %3d",sfx_volume);
5337 strcpy(str_s,pan_str[pan_style]);
5338 sprintf(str_leftmod1,"%3d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5339 sprintf(str_leftmod2,"%3d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5340 sprintf(str_rightmod1,"%3d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5341 sprintf(str_rightmod2,"%3d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5342 break;
5343 }
5344 }
5345
5346 return D_O_K;
5347 }
5348
5349 int32_t set_vol(void *dp3, int32_t d2)
5350 {
5351 switch(((int32_t*)dp3)[0])
5352 {
5353 case 0:
5354 midi_volume = zc_min(d2<<3,255);
5355 break;
5356
5357 case 1:
5358 digi_volume = zc_min(d2<<3,255);
5359 break;
5360
5361 case 2:
5362 emusic_volume = zc_min(d2<<3,255);
5363 break;
5364
5365 case 3:
5366 sfx_volume = zc_min(d2<<3,255);
5367 break;
5368 }
5369
5370 // text_mode(vc(11));
5371 textprintf_right_ex(screen,get_zc_font(font_lfont_l), ((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX]," %3d",zc_min(d2<<3,255));
5372 return D_O_K;
5373 }
5374
5375 int32_t set_pan(void *dp3, int32_t d2)
5376 {
5377 pan_style = vbound(d2,0,3);
5378 // text_mode(vc(11));
5379 textout_right_ex(screen,get_zc_font(font_lfont_l), pan_str[pan_style],((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5380 return D_O_K;
5381 }
5382
5383 static int32_t gamepad_joys_list[] =
5384 {
5385 61,
5386 -1
5387 };
5388
5389 static int32_t gamepad_btn_list[] =
5390 {
5391 6,
5392 7,8,9,10,11,12,13,14,15,16,17,
5393 18,19,20,21,22,23,24,25,26,27,28,
5394 29,30,31,32,33,34,35,36,37,38,39,
5395 -1
5396 };
5397
5398 static int32_t gamepad_dirs_list[] =
5399 {
5400 40,41,42,43,
5401 44,45,46,47,
5402 48,49,50,51,
5403 52,53,54,55,
5404 56,57,58,59,
5405 60,
5406 -1
5407 };
5408
5409 static TABPANEL gamepad_tabs[] =
5410 {
5411 // (text)
5412 { (char *)"Controllers", D_SELECTED, gamepad_joys_list, 0, NULL },
5413 { (char *)"Buttons", 0, gamepad_btn_list, 0, NULL },
5414 { (char *)"Directions", 0, gamepad_dirs_list, 0, NULL },
5415 { NULL, 0, NULL, 0, NULL }
5416 };
5417
5418 const char *joy_list(int32_t index, int32_t *list_size)
5419 {
5420 if (index == -1)
5421 {
5422 *list_size = al_get_num_joysticks();
5423 return NULL;
5424 }
5425
5426 ALLEGRO_JOYSTICK* joy = al_get_joystick(index);
5427 if (!joy)
5428 {
5429 return "?";
5430 }
5431
5432 return al_get_joystick_name(joy);
5433 }
5434
5435 409 static ListData joy__list(joy_list, &font);
5436
5437 static int32_t d_joylist_proc(int32_t msg,DIALOG *d,int32_t c)
5438 {
5439 int32_t d2 = d->d2;
5440 int32_t ret = jwin_droplist_proc(msg,d,c);
5441
5442 if(d2!=d->d2)
5443 {
5444 joystick_index = d->d2;
5445 ret |= D_REDRAW_ALL;
5446 }
5447
5448 return ret;
5449 }
5450
5451 static DIALOG gamepad_dlg[] =
5452 {
5453 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5454 { jwin_win_proc, 8, 24, 304, 256, 0, 0, 0, D_EXIT, 0, 0, (void *) "Gamepad Controls", NULL, NULL },
5455 { jwin_tab_proc, 8+4, 24+23,304-8,256-52,vc(0), vc(15), 0, 0, 0, 0, (void *) gamepad_tabs, NULL, (void *)gamepad_dlg },
5456 { d_stringloader, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5457 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5458 { jwin_button_proc, 90, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5459 { jwin_button_proc, 170, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5460 // 6
5461 { d_dummy_proc, 14, 61, 294, 192, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5462 // 7
5463 { jwin_ctext_proc, 92, 92-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5464 { jwin_ctext_proc, 92, 120-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_b, NULL, NULL },
5465 { jwin_ctext_proc, 92, 148-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5466 { jwin_ctext_proc, 92, 180-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex1, NULL, NULL },
5467 { jwin_ctext_proc, 92, 212-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex3, NULL, NULL },
5468 { jwin_ctext_proc, 237, 92-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_l, NULL, NULL },
5469 { jwin_ctext_proc, 237, 120-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_r, NULL, NULL },
5470 { jwin_ctext_proc, 237, 148-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_p, NULL, NULL },
5471 { jwin_ctext_proc, 237, 180-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex2, NULL, NULL },
5472 { jwin_ctext_proc, 237, 212-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex4, NULL, NULL },
5473 { jwin_ctext_proc, 92, 244-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_m, NULL, NULL },
5474 // 18
5475 { d_jbutton_proc, 22, 90-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "A", NULL, &Abtn},
5476 { d_jbutton_proc, 22, 118-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "B", NULL, &Bbtn},
5477 { d_jbutton_proc, 22, 146-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start", NULL, &Sbtn},
5478 { d_jbutton_proc, 22, 178-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "X (EX1)", NULL, &Exbtn1},
5479 { d_jbutton_proc, 22, 210-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX3", NULL, &Exbtn3},
5480 { d_jbutton_proc, 167, 90-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "L", NULL, &Lbtn},
5481 { d_jbutton_proc, 167, 118-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "R", NULL, &Rbtn},
5482 { d_jbutton_proc, 167, 146-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map", NULL, &Pbtn},
5483 { d_jbutton_proc, 167, 178-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Y (EX2)", NULL, &Exbtn2},
5484 { d_jbutton_proc, 167, 210-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX4", NULL, &Exbtn4},
5485 { d_jbutton_proc, 22, 242-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Menu", NULL, &Mbtn},
5486 // 29
5487 { d_j_clearbutton_proc, 22+91, 90-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Abtn},
5488 { d_j_clearbutton_proc, 22+91, 118-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Bbtn},
5489 { d_j_clearbutton_proc, 22+91, 146-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Sbtn},
5490 { d_j_clearbutton_proc, 22+91, 178-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn1},
5491 { d_j_clearbutton_proc, 22+91, 210-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn3},
5492 { d_j_clearbutton_proc, 167+91, 90-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Lbtn},
5493 { d_j_clearbutton_proc, 167+91, 118-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Rbtn},
5494 { d_j_clearbutton_proc, 167+91, 146-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Pbtn},
5495 { d_j_clearbutton_proc, 167+91, 178-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn2},
5496 { d_j_clearbutton_proc, 167+91, 210-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn4},
5497 { d_j_clearbutton_proc, 22+91, 242-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Mbtn},
5498 // 40
5499 { jwin_frame_proc, 14, 62, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5500 { jwin_frame_proc, 159, 62, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5501 { jwin_text_proc, 30, 68, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Vertical", NULL, NULL },
5502 { jwin_text_proc, 175, 68, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Horizontal", NULL, NULL },
5503 // 44
5504 { jwin_text_proc, 92, 84, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_up, NULL, NULL },
5505 { jwin_text_proc, 92, 112, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_down, NULL, NULL },
5506 { jwin_text_proc, 237, 84, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_left, NULL, NULL },
5507 { jwin_text_proc, 237, 112, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_right, NULL, NULL },
5508 // 48
5509 { d_jbutton_proc, 22, 82, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Up", NULL, &DUbtn },
5510 { d_jbutton_proc, 22, 110, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Down", NULL, &DDbtn },
5511 { d_jbutton_proc, 167, 82, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Left", NULL, &DLbtn },
5512 { d_jbutton_proc, 167, 110, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Right", NULL, &DRbtn },
5513 // 52
5514 { d_j_clearbutton_proc, 22+91, 82, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DUbtn},
5515 { d_j_clearbutton_proc, 22+91, 110, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DDbtn},
5516 { d_j_clearbutton_proc, 167+91, 82, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DLbtn},
5517 { d_j_clearbutton_proc, 167+91, 110, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DRbtn},
5518 // 56
5519 { jwin_check_proc, 22, 150, 147, 8, vc(14), vc(1), 0, 0, 1, 0, (void *) "Primary: Use Analog Stick (Ignore above and use below instead)", NULL, NULL },
5520 { d_jstick_proc, 22, 165, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Primary", NULL, &js_stick_1_x_stick },
5521 { d_jstick_proc, 22, 195, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Secondary", NULL, &js_stick_2_x_stick },
5522 { jwin_text_proc, 90, 165, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_primary_stick, NULL, NULL },
5523 { jwin_text_proc, 90, 195, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_secondary_stick, NULL, NULL },
5524
5525 // 61
5526 { d_joylist_proc, 22, 62, 150, 16, 0, 0, 0, 0, 0, 0, (void *) &joy__list, NULL, NULL },
5527
5528 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5529 };
5530
5531 static int32_t keyboard_keys_list[] =
5532 {
5533 6,7,8,9,10,
5534 11,12,13,14,15,16,17,18,19,20,
5535 21,22,23,24,25,26,27,28,29,30,
5536 31,32,33,34,35,36,37,38,39,40,
5537 -1
5538 };
5539
5540 static int32_t keyboard_dirs_list[] =
5541 {
5542 41,42,43,44,
5543 45,46,47,48,
5544 49,50,51,52,
5545 53,54,55,56,
5546 -1
5547 };
5548
5549 static int32_t keyboard_mods_list[] =
5550 {
5551 57,58,59,60,
5552 61,62,63,64,
5553 65,66,67,68,
5554 69,70,71,72,
5555 -1
5556 };
5557
5558 static TABPANEL keyboard_control_tabs[] =
5559 {
5560 // (text)
5561 { (char *)"Keys", D_SELECTED, keyboard_keys_list, 0, NULL },
5562 { (char *)"Directions", 0, keyboard_dirs_list, 0, NULL },
5563 { (char *)"Cheat Mods", 0, keyboard_mods_list, 0, NULL },
5564 { NULL, 0, NULL, 0, NULL }
5565 };
5566
5567 static DIALOG keyboard_control_dlg[] =
5568 {
5569 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5570 { jwin_win_proc, 8, 39, 304, 240, 0, 0, 0, D_EXIT, 0, 0, (void *) "Keyboard Controls", NULL, NULL },
5571 { jwin_tab_proc, 8+4, 39+23,304-8,240-56,vc(0), vc(15), 0, 0, 0, 0, (void *) keyboard_control_tabs, NULL, (void *)keyboard_control_dlg },
5572 { d_stringloader, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5573 { jwin_button_proc, 90, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5574 { jwin_button_proc, 170, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5575 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5576 // Keys
5577 // 6
5578 { jwin_frame_proc, 14, 80, 148, 105, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5579 { jwin_frame_proc, 158, 80, 148, 105, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5580 { jwin_frame_proc, 14, 181, 292, 67, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5581 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Standard", NULL, NULL },
5582 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Extended", NULL, NULL },
5583 // 11
5584 { jwin_text_proc, 92-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5585 { jwin_text_proc, 92-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_b, NULL, NULL },
5586 { jwin_text_proc, 92-4, 158, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5587 { jwin_text_proc, 92-4, 190, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex1, NULL, NULL },
5588 { jwin_text_proc, 92-4, 222, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex3, NULL, NULL },
5589 { jwin_text_proc, 237-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_l, NULL, NULL },
5590 { jwin_text_proc, 237-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_r, NULL, NULL },
5591 { jwin_text_proc, 237-4, 158, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_p, NULL, NULL },
5592 { jwin_text_proc, 237-4, 190, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex2, NULL, NULL },
5593 { jwin_text_proc, 237-4, 222, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex4, NULL, NULL },
5594 // 21
5595 { d_kbutton_proc, 22, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "A", NULL, &Akey},
5596 { d_kbutton_proc, 22, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "B", NULL, &Bkey},
5597 { d_kbutton_proc, 22, 156, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start", NULL, &Skey},
5598 { d_kbutton_proc, 22, 188, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "X (EX1)", NULL, &Exkey1},
5599 { d_kbutton_proc, 22, 220, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX3", NULL, &Exkey3},
5600 { d_kbutton_proc, 167, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "L", NULL, &Lkey},
5601 { d_kbutton_proc, 167, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "R", NULL, &Rkey},
5602 { d_kbutton_proc, 167, 156, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map", NULL, &Pkey},
5603 { d_kbutton_proc, 167, 188, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Y (EX2)", NULL, &Exkey2},
5604 { d_kbutton_proc, 167, 220, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX4", NULL, &Exkey4},
5605 // 31
5606 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Akey},
5607 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Bkey},
5608 { d_k_clearbutton_proc, 22+91, 156, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Skey},
5609 { d_k_clearbutton_proc, 22+91, 188, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey1},
5610 { d_k_clearbutton_proc, 22+91, 220, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey3},
5611 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Lkey},
5612 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Rkey},
5613 { d_k_clearbutton_proc, 167+91, 156, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Pkey},
5614 { d_k_clearbutton_proc, 167+91, 188, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey2},
5615 { d_k_clearbutton_proc, 167+91, 220, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey4},
5616 // Dirs
5617 // 41
5618 { jwin_frame_proc, 14, 80, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5619 { jwin_frame_proc, 159, 80, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5620 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Vertical", NULL, NULL },
5621 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Horizontal", NULL, NULL },
5622 // 45
5623 { jwin_text_proc, 92-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_up, NULL, NULL },
5624 { jwin_text_proc, 92-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_down, NULL, NULL },
5625 { jwin_text_proc, 237-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_left, NULL, NULL },
5626 { jwin_text_proc, 237-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_right, NULL, NULL },
5627 // 49
5628 { d_kbutton_proc, 22, 100, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Up", NULL, &DUkey},
5629 { d_kbutton_proc, 22, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Down", NULL, &DDkey},
5630 { d_kbutton_proc, 167, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Left", NULL, &DLkey},
5631 { d_kbutton_proc, 167, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Right", NULL, &DRkey},
5632 // 53
5633 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DUkey},
5634 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DDkey},
5635 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DLkey},
5636 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DRkey},
5637 // Mods
5638 // 57
5639 { jwin_frame_proc, 14, 80, 148, 140-58, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5640 { jwin_frame_proc, 158, 80, 148, 140-58, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5641 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Left", NULL, NULL },
5642 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Right", NULL, NULL },
5643 // 61
5644 { jwin_text_proc, 92-26, 101, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_leftmod1, NULL, NULL },
5645 { jwin_text_proc, 92-26, 129, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_rightmod1, NULL, NULL },
5646 { jwin_text_proc, 237-4-22,101, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_leftmod2, NULL, NULL },
5647 { jwin_text_proc, 237-4-22,129, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_rightmod2, NULL, NULL },
5648 // 65
5649 { d_kbutton_proc, 22, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Main", NULL, &cheat_modifier_keys[0]},
5650 { d_kbutton_proc, 22, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Second", NULL, &cheat_modifier_keys[2]},
5651 { d_kbutton_proc, 167, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Main", NULL, &cheat_modifier_keys[1]},
5652 { d_kbutton_proc, 167, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Second", NULL, &cheat_modifier_keys[3]},
5653 // 69
5654 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[0]},
5655 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[2]},
5656 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[1]},
5657 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[3]},
5658 // 73
5659 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5660 };
5661
5662 int32_t midi_dp[3] = {0,0,0};
5663 int32_t emus_dp[3] = {2,0,0};
5664 int32_t sfx_dp[3] = {3,0,0};
5665 int32_t pan_dp[3] = {0,0,0};
5666
5667 static DIALOG sound_dlg[] =
5668 {
5669 //(dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5670 409 { jwin_win_proc, 0, 0, 320, 178, 0, 0, 0, D_EXIT, 0, 0, (void *) "Sound Settings", NULL, NULL },
5671 409 { d_stringloader, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5672 409 { jwin_button_proc, 58, 148, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5673 409 { jwin_button_proc, 138, 148, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5674 409 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5675 409 { jwin_frame_proc, 10, 28, 300, 112, 0, 0, 0, 0, FR_ETCHED, 0, NULL, NULL, NULL },
5676 409 { jwin_rtext_proc, 190, 40, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_a, NULL, NULL },
5677 409 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5678 409 { jwin_rtext_proc, 190, 56, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_l, NULL, NULL },
5679 409 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5680 // 10
5681 409 { jwin_rtext_proc, 190, 72, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_r, NULL, NULL },
5682 409 { jwin_rtext_proc, 190, 88, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_s, NULL, NULL },
5683 409 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5684 409 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5685 409 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5686 409 { jwin_slider_proc, 196, 40, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, midi_dp },
5687 409 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5688 409 { jwin_slider_proc, 196, 56, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, emus_dp },
5689 409 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5690 409 { jwin_slider_proc, 196, 72, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, sfx_dp },
5691 //20
5692 409 { jwin_slider_proc, 196, 88, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 3, 0, NULL, (void *) set_pan, pan_dp },
5693 409 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5694 409 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5695 409 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5696 409 { jwin_text_proc, 17, 40, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "MIDI Volume", NULL, NULL },
5697 409 { jwin_text_proc, 17, 56, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Music Volume (Enhanced Music)", NULL, NULL },
5698 409 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5699 409 { jwin_text_proc, 17, 72, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "SFX Volume", NULL, NULL },
5700 409 { jwin_text_proc, 17, 88, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "SFX Pan", NULL, NULL },
5701 409 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5702 //30
5703 409 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5704 409 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5705 409 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5706 };
5707
5708 char zc_builddate[80];
5709 char zc_aboutstr[80];
5710
5711 static DIALOG about_dlg[] =
5712 {
5713 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5714 { jwin_win_proc, 68, 52, 184, 154, 0, 0, 0, D_EXIT, 0, 0, (void *) "About", NULL, NULL },
5715 { jwin_button_proc, 140, 176, 41, 21, vc(14), 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5716 { jwin_ctext_proc, 160, 84, 0, 8, vc(0), vc(11), 0, 0, 0, 0, zc_aboutstr, NULL, NULL },
5717 { jwin_ctext_proc, 160, 92, 0, 8, vc(0) , vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5718 { jwin_ctext_proc, 160, 100, 0, 8, vc(0) , vc(11), 0, 0, 0, 0, zc_builddate, NULL, NULL },
5719 { jwin_text_proc, 88, 124, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Coded by:", NULL, NULL },
5720 { jwin_text_proc, 88, 132, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) " Phantom Menace", NULL, NULL },
5721 { jwin_text_proc, 88, 144, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Produced by:", NULL, NULL },
5722 { jwin_text_proc, 88, 152, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) " Armageddon Games", NULL, NULL },
5723 { jwin_frame_proc, 80, 117, 160, 50, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5724 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5725 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5726 };
5727
5728
5729 static DIALOG quest_dlg[] =
5730 {
5731 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5732 { jwin_win_proc, 68, 25, 184, 190, 0, 0, 0, D_EXIT, 0, 0, (void *) "Quest Info", NULL, NULL },
5733 { jwin_edit_proc, 84, 54, 152, 16, 0, 0, 0, D_READONLY, 100, 0, NULL, NULL, NULL },
5734 { jwin_text_proc, 89, 84, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Number:", NULL, NULL },
5735 { jwin_text_proc, 152, 84, 24, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5736 { jwin_text_proc, 89, 94, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Version:", NULL, NULL },
5737 { jwin_text_proc, 160, 94, 64, 8, vc(7), vc(11), 0, 0, 0, 0, header_version_nul_term, NULL, NULL },
5738 { jwin_text_proc, 89, 104, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "ZQ Version:", NULL, NULL },
5739 { jwin_text_proc, 130, 104, 64, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5740 { jwin_text_proc, 84, 126, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Title:", NULL, NULL },
5741 { jwin_textbox_proc, 84, 136, 152, 24, 0, 0, 0, 0, 0, 0, QHeader.title, NULL, NULL },
5742 { jwin_text_proc, 84, 168, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Author:", NULL, NULL },
5743 { jwin_textbox_proc, 84, 178, 152, 24, 0, 0, 0, 0, 0, 0, QHeader.author, NULL, NULL },
5744 { jwin_frame_proc, 84, 79, 152, 38, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5745 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5746 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5747 };
5748
5749 static DIALOG triforce_dlg[] =
5750 {
5751 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
5752 { jwin_win_proc, 72, 64, 177, 105, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Triforce Pieces", NULL, NULL },
5753 // 1
5754 { jwin_check_proc, 129, 94, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "1", NULL, NULL },
5755 { jwin_check_proc, 129, 104, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "2", NULL, NULL },
5756 { jwin_check_proc, 129, 114, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "3", NULL, NULL },
5757 { jwin_check_proc, 129, 124, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "4", NULL, NULL },
5758 { jwin_check_proc, 172, 94, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "5", NULL, NULL },
5759 { jwin_check_proc, 172, 104, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "6", NULL, NULL },
5760 { jwin_check_proc, 172, 114, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "7", NULL, NULL },
5761 { jwin_check_proc, 172, 124, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "8", NULL, NULL },
5762 // 9
5763 { jwin_button_proc, 90, 144, 61, 21, vc(0), vc(11), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
5764 { jwin_button_proc, 170, 144, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5765 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5766 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5767 };
5768
5769 int32_t onToggleRecordingNewSaves()
5770 {
5771 if (zc_get_config("zeldadx", "replay_new_saves", false))
5772 {
5773 zc_set_config("zeldadx", "replay_new_saves", false);
5774 }
5775 else
5776 {
5777 zc_set_config("zeldadx", "replay_new_saves", true);
5778 jwin_alert("Recording", "Newly created saves will be recorded and written to a replay file.",
5779 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5780 }
5781 return D_O_K;
5782 }
5783
5784 #ifdef HAS_CURL
5785 int32_t onToggleAutoUploadReplays()
5786 {
5787 if (zc_get_config("zeldadx", "replay_upload", false))
5788 {
5789 zc_set_config("zeldadx", "replay_upload", false);
5790 }
5791 else
5792 {
5793 zc_set_config("zeldadx", "replay_upload", true);
5794 jwin_alert("Replays", "Replays will be automatically uploaded. This helps development by",
5795 " preventing bugs and simplifying bug reports.",
5796 "Upload will happen no more than once a week when closing ZC",
5797 "OK",NULL,13,27,get_zc_font(font_lfont));
5798
5799 if (!zc_get_config("zeldadx", "replay_new_saves", false))
5800 onToggleRecordingNewSaves();
5801 }
5802 return D_O_K;
5803 }
5804
5805 int32_t onUploadReplays()
5806 {
5807 if(jwin_alert3(
5808 "Upload replays",
5809 "Upload your replays now to assist in development?",
5810 NULL,
5811 NULL,
5812 "&Yes",
5813 "&No",
5814 NULL,
5815 'y',
5816 'n',
5817 0,
5818 get_zc_font(font_lfont)) == 1)
5819 {
5820 int num_uploaded = replay_upload();
5821 jwin_alert("Upload replays", fmt::format("Uploaded {} replays", num_uploaded).c_str(),
5822 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5823 }
5824 return D_O_K;
5825 }
5826
5827 int32_t onClearUploadCache()
5828 {
5829 if(jwin_alert3(
5830 "Upload replays",
5831 "Clear the upload cache?",
5832 "This simply deletes replays/state.json. There's no harm in doing this, but",
5833 "likely is not necessary.",
5834 "&Yes",
5835 "&No",
5836 NULL,
5837 'y',
5838 'n',
5839 0,
5840 get_zc_font(font_lfont)) == 1)
5841 {
5842 replay_upload_clear_cache();
5843 }
5844 return D_O_K;
5845 }
5846 #endif
5847
5848 int32_t onToggleSnapshotAllFrames()
5849 {
5850 replay_set_snapshot_all_frames(!replay_is_snapshot_all_frames());
5851 return D_O_K;
5852 }
5853
5854 int32_t onStopReplayOrRecord()
5855 {
5856 if (replay_is_replaying())
5857 {
5858 replay_quit();
5859 }
5860 else if (replay_get_mode() == ReplayMode::Record)
5861 {
5862 if (!replay_get_meta_bool("test_mode"))
5863 {
5864 jwin_alert("Recording", "You cannot stop recording a save file.",
5865 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5866 return D_CLOSE;
5867 }
5868
5869 if (jwin_alert("Stop Recording",
5870 "Save replay to disk and stop recording?",
5871 "This will stop the recording.",
5872 NULL,
5873 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5874 return D_CLOSE;
5875
5876 replay_save();
5877 replay_stop();
5878 }
5879 return D_O_K;
5880 }
5881
5882 static int32_t handle_on_load_replay(ReplayMode mode)
5883 {
5884 bool ctrl = CHECK_CTRL_CMD;
5885 if (Playing)
5886 {
5887 if (jwin_alert("Replay - Warning!",
5888 "Loading a replay will exit the current game.",
5889 "All unsaved progress will be lost.",
5890 "Do you wish to continue?",
5891 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5892 return D_CLOSE;
5893 }
5894
5895 std::string mode_string = replay_mode_to_string(mode);
5896 mode_string[0] = std::toupper(mode_string[0]);
5897
5898 std::string line_1 = "Select a replay file to play back.";
5899 std::string line_2 = "You won't be able to save, and it won't effect existing saves.";
5900 std::string line_3 = "You can stop the replay and take over manually any time.";
5901 if (mode == ReplayMode::Update)
5902 {
5903 line_1 = "Select a replay file to update.";
5904 line_2 = "WARNING: be sure to back up the zplay file";
5905 line_3 = "and verify that the updated replay works as expected!";
5906 }
5907
5908 if (jwin_alert(mode_string.c_str(),
5909 line_1.c_str(),
5910 line_2.c_str(),
5911 line_3.c_str(),
5912 "OK","Nevermind",13,27,get_zc_font(font_lfont)) == 1)
5913 {
5914 std::string replay_path = "replays/";
5915 if(ctrl && devpwd())
5916 replay_path = "../../tests/replays/";
5917 std::string prompt = fmt::format("Load Replay ({})", REPLAY_EXTENSION);
5918 if (auto result = prompt_for_existing_file(prompt, REPLAY_EXTENSION, nullptr, replay_path))
5919 replay_path = *result;
5920 else
5921 return D_CLOSE;
5922
5923 replay_quit();
5924 load_replay_file_deferred(mode, replay_path);
5925 Quit = qRESET;
5926 return D_CLOSE;
5927 }
5928 return D_O_K;
5929 }
5930
5931 int32_t onLoadReplay()
5932 {
5933 return handle_on_load_replay(ReplayMode::Replay);
5934 }
5935
5936 int32_t onLoadReplayAssert()
5937 {
5938 return handle_on_load_replay(ReplayMode::Assert);
5939 }
5940
5941 int32_t onLoadReplayUpdate()
5942 {
5943 return handle_on_load_replay(ReplayMode::Update);
5944 }
5945
5946 int32_t onSaveReplay()
5947 {
5948 if (replay_get_mode() == ReplayMode::Record)
5949 {
5950 if (!replay_get_meta_bool("test_mode"))
5951 {
5952 if (jwin_alert("Save Replay",
5953 "This will save a copy of the replay up to this point.",
5954 "The official replay file will be untouched.",
5955 "Do you wish to continue?",
5956 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5957 {
5958 return D_CLOSE;
5959 }
5960
5961 std::string replay_path = replay_get_replay_path().string();
5962 std::string prompt = fmt::format("Save Replay ({})", REPLAY_EXTENSION);
5963 if (auto result = prompt_for_new_file(prompt, REPLAY_EXTENSION, nullptr, replay_path))
5964 replay_path = *result;
5965 else
5966 return D_CLOSE;
5967
5968 if (fileexists(replay_path.c_str()))
5969 {
5970 jwin_alert("Save Replay", "You cannot overwrite an existing file.",
5971 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5972 return D_CLOSE;
5973 }
5974
5975 replay_save(replay_path);
5976 }
5977 else
5978 {
5979 replay_save();
5980 }
5981 }
5982 return D_O_K;
5983 }
5984
5985 enum
5986 {
5987 MENUID_REPLAY_RECORDNEW,
5988 MENUID_REPLAY_STOP,
5989 MENUID_REPLAY_SAVE,
5990 MENUID_REPLAY_SNAP_ALL,
5991 MENUID_REPLAY_AUTOUPLOAD,
5992 MENUID_REPLAY_UPLOAD,
5993 MENUID_REPLAY_CLEARUPLOADCACHE,
5994 };
5995
1/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
409 static NewMenu replay_menu
5996 5317 {
5997
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Record new saves", onToggleRecordingNewSaves, MENUID_REPLAY_RECORDNEW },
5998
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 {},
5999
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Stop replay", onStopReplayOrRecord, MENUID_REPLAY_STOP },
6000
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Load replay", onLoadReplay },
6001
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Load replay (assert)", onLoadReplayAssert },
6002
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Load replay (update)", onLoadReplayUpdate },
6003
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Save replay", onSaveReplay, MENUID_REPLAY_SAVE },
6004
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Snapshot all frames", onToggleSnapshotAllFrames, MENUID_REPLAY_SNAP_ALL },
6005 #ifdef HAS_CURL
6006
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 {},
6007
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Auto upload replays", onToggleAutoUploadReplays, MENUID_REPLAY_AUTOUPLOAD },
6008
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Upload replays", onUploadReplays, MENUID_REPLAY_UPLOAD },
6009
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Clear upload cache", onClearUploadCache, MENUID_REPLAY_CLEARUPLOADCACHE },
6010 #endif
6011 };
6012
6013 static DIALOG credits_dlg[] =
6014 {
6015 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6016 { jwin_win_proc, 40, 38, 241, 173, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "ZQuest Classic Credits", NULL, NULL },
6017 { jwin_frame_proc, 47, 65, 227, 115, vc(15), vc(1), 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
6018 { d_bitmap_proc, 49, 67, 222, 110, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6019 { jwin_button_proc, 140, 184, 41, 21, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6020 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6021 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6022 };
6023
6024 409 static ListData dmap_list(dmaplist, &font);
6025
6026 static DIALOG goto_dlg[] =
6027 {
6028 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6029 { jwin_win_proc, 48, 25, 205, 100, 0, 0, 0, D_EXIT, 0, 0, (void *) "Goto Location", NULL, NULL },
6030 { jwin_button_proc, 90, 176-78, 61, 21, vc(14), 0, 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6031 { jwin_button_proc, 170, 176-78, 61, 21, vc(14), 0, 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6032 { jwin_text_proc, 55, 129-75, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "DMap:", NULL, NULL },
6033 { jwin_droplist_proc, 88, 126-75, 160, 16, 0, 0, 0, 0, 0, 0, (void *) &dmap_list, NULL, NULL },
6034 { jwin_text_proc, 55, 149-75, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Screen:", NULL, NULL },
6035 { jwin_edit_proc, 132, 146-75, 91, 16, 0, 0, 0, 0, 2, 0, NULL, NULL, NULL },
6036 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6037 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6038 };
6039
6040 int32_t onGoTo()
6041 {
6042 bool music = false;
6043 music = music;
6044 sprintf(cheat_goto_screen_str,"%X",cheat_goto_screen);
6045
6046 goto_dlg[0].dp2=get_zc_font(font_lfont);
6047 goto_dlg[4].d2=cheat_goto_dmap;
6048 goto_dlg[6].dp=cheat_goto_screen_str;
6049
6050 clear_keybuf();
6051
6052 large_dialog(goto_dlg);
6053
6054 if(do_zqdialog(goto_dlg,4)==1)
6055 {
6056 int dmap = goto_dlg[4].d2;
6057 int screen = zc_xtoi(cheat_goto_screen_str);
6058 int adjusted_screen = screen + DMaps[dmap].xoff;
6059 if (adjusted_screen < 0 || adjusted_screen >= 128)
6060 {
6061 InfoDialog("Invalid screen", fmt::format("The screen {:02X} is out of bounds.", adjusted_screen)).show();
6062 }
6063 else
6064 {
6065 cheats_enqueue(Cheat::GoTo, dmap, screen);
6066 }
6067 };
6068
6069 return D_O_K;
6070 }
6071
6072 int32_t onGoToComplete()
6073 {
6074 if(!Playing)
6075 {
6076 return D_O_K;
6077 }
6078
6079 enter_sys_pal();
6080 music_pause();
6081 pause_all_sfx();
6082 onGoTo();
6083 eat_buttons();
6084
6085 zc_readrawkey(KEY_ESC);
6086
6087 exit_sys_pal();
6088 music_resume();
6089 resume_all_sfx();
6090 return D_O_K;
6091 }
6092
6093 int32_t onCredits()
6094 {
6095 return D_O_K;
6096 }
6097
6098 const char *midilist(int32_t index, int32_t *list_size)
6099 {
6100 if(index<0)
6101 {
6102 *list_size=0;
6103
6104 for(int32_t i=0; i<MAXMIDIS; i++)
6105 if(tunes[i].data)
6106 ++(*list_size);
6107
6108 return NULL;
6109 }
6110
6111 int32_t i=0,m=0;
6112
6113 while(m<=index && i<=MAXMIDIS)
6114 {
6115 if(tunes[i].data)
6116 ++m;
6117
6118 ++i;
6119 }
6120
6121 --i;
6122
6123 if(i==MAXMIDIS && m<index)
6124 return "(null)";
6125
6126 return tunes[i].title;
6127 }
6128
6129 /* ------- MIDI info stuff -------- */
6130
6131 char *text;
6132 midi_info *zmi;
6133 bool dialog_running;
6134 bool listening;
6135
6136 void get_info(int32_t index);
6137
6138 int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c)
6139 {
6140 int32_t d2 = d->d2;
6141 int32_t ret = jwin_droplist_proc(msg,d,c);
6142
6143 if(d2!=d->d2)
6144 {
6145 get_info(d->d2);
6146 }
6147
6148 return ret;
6149 }
6150
6151 int32_t d_listen_proc(int32_t msg,DIALOG *d,int32_t c)
6152 {
6153 /* 'd->d1' is offset from 'd' in DIALOG array to midilist proc */
6154
6155 int32_t ret = jwin_button_proc(msg,d,c);
6156
6157 if(ret == D_CLOSE)
6158 {
6159 // get current midi index
6160 int32_t index = (d+(d->d1))->d2;
6161 int32_t i=0, m=0;
6162
6163 while(m<=index && i<=MAXMIDIS)
6164 {
6165 if(tunes[i].data)
6166 ++m;
6167
6168 ++i;
6169 }
6170
6171 --i;
6172 jukebox(i);
6173 listening = true;
6174 ret = D_O_K;
6175 }
6176
6177 return ret;
6178 }
6179
6180 int32_t d_savemidi_proc(int32_t msg,DIALOG *d,int32_t c)
6181 {
6182 /* 'd->d1' is offset from 'd' in DIALOG array to midilist proc */
6183
6184 int32_t ret = jwin_button_proc(msg,d,c);
6185
6186 if(ret == D_CLOSE)
6187 {
6188 // get current midi index
6189 int32_t index = (d+(d->d1))->d2;
6190 int32_t i=0, m=0;
6191
6192 while(m<=index && i<=MAXMIDIS)
6193 {
6194 if(tunes[i].data)
6195 ++m;
6196
6197 ++i;
6198 }
6199
6200 --i;
6201
6202 char title[40] = "Save MIDI: ";
6203 static EXT_LIST list[] =
6204 {
6205 { (char *)"MIDI files (*.mid)", (char *)"mid" },
6206 { NULL, NULL }
6207 };
6208
6209 strcpy(title+11, tunes[i].title);
6210 title[39] = '\0';
6211
6212 std::string fname;
6213 if (auto result = prompt_for_new_file(title, "", list, "tune.mid"))
6214 fname = *result;
6215 else
6216 goto done;
6217
6218 if(exists(fname.c_str()))
6219 {
6220 if(jwin_alert(title, fname.c_str(), "already exists.", "Overwrite it?", "&Yes","&No",'y','n',get_zc_font(font_lfont))==2)
6221 goto done;
6222 }
6223
6224 // save midi i
6225
6226 if (save_midi(fname.c_str(), tunes[i].data) != 0)
6227 jwin_alert(title, "Error saving MIDI to", fname.c_str(), NULL, "Darn", NULL,13,27,get_zc_font(font_lfont));
6228
6229 done:
6230 chop_path(fname.data());
6231 ret = D_REDRAW;
6232 }
6233
6234 return ret;
6235 }
6236
6237 409 static ListData midi_list(midilist, &font);
6238
6239 static DIALOG midi_dlg[] =
6240 {
6241 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6242 { jwin_win_proc, 8, 28, 304, 184, 0, 0, 0, D_EXIT, 0, 0, (void *) "MIDI Info", NULL, NULL },
6243 { jwin_text_proc, 32, 60, 40, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Tune:", NULL, NULL },
6244 { d_midilist_proc, 80, 56, 192, 16, 0, 0, 0, 0, 0, 0, (void *) &midi_list, NULL, NULL },
6245 { jwin_textbox_proc, 15, 80, 290, 96, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6246 { d_listen_proc, 24, 183, 72, 21, 0, 0, 'l', D_EXIT, -2, 0, (void *) "&Listen", NULL, NULL },
6247 { d_savemidi_proc, 108, 183, 72, 21, 0, 0, 's', D_EXIT, -3, 0, (void *) "&Save", NULL, NULL },
6248 { jwin_button_proc, 236, 183, 61, 21, 0, 0, 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
6249 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6250 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6251 };
6252
6253 void get_info(int32_t index)
6254 {
6255 int32_t i=0, m=0;
6256
6257 while(m<=index && i<=MAXMIDIS)
6258 {
6259 if(tunes[i].data)
6260 ++m;
6261
6262 ++i;
6263 }
6264
6265 --i;
6266
6267 if(i==MAXMIDIS && m<index)
6268 strcpy(text,"(null)");
6269 else
6270 {
6271 get_midi_info(tunes[i].data,zmi);
6272 get_midi_text(tunes[i].data,zmi,text);
6273 }
6274
6275 midi_dlg[0].dp2=get_zc_font(font_lfont);
6276 midi_dlg[3].dp = text;
6277 midi_dlg[3].d1 = midi_dlg[3].d2 = 0;
6278 midi_dlg[5].flags = (tunes[i].flags&tfDISABLESAVE) ? D_DISABLED : D_EXIT;
6279
6280 if(dialog_running)
6281 {
6282 jwin_textbox_proc(MSG_DRAW,midi_dlg+3,0);
6283 d_savemidi_proc(MSG_DRAW,midi_dlg+5,0);
6284 }
6285 }
6286
6287 int32_t onMIDICredits()
6288 {
6289 text = (char*)malloc(4096);
6290 zmi = (midi_info*)malloc(sizeof(midi_info));
6291
6292 if(!text || !zmi)
6293 {
6294 jwin_alert(NULL,"Not enough memory",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
6295 return D_O_K;
6296 }
6297
6298 bool do_pause_midi = midi_pos >= 0 && currmidi;
6299 auto restore_midi = currmidi;
6300 if(do_pause_midi)
6301 {
6302 paused_midi_pos = midi_pos;
6303 stop_midi();
6304 midi_suspended = midissuspHALTED;
6305 }
6306
6307 midi_dlg[0].dp2=get_zc_font(font_lfont);
6308 midi_dlg[2].d1 = 0;
6309 midi_dlg[2].d2 = 0;
6310 midi_dlg[4].flags = D_EXIT;
6311 midi_dlg[5].flags = (tunes[midi_dlg[2].d1].flags&tfDISABLESAVE) ? D_DISABLED : D_EXIT;
6312
6313 listening = false;
6314 dialog_running=false;
6315 get_info(0);
6316
6317 dialog_running=true;
6318
6319 large_dialog(midi_dlg);
6320
6321 do_zqdialog(midi_dlg,0);
6322 dialog_running=false;
6323
6324 if(listening)
6325 music_stop();
6326
6327 if(do_pause_midi)
6328 {
6329 // TODO: this probably doesn't resume midis nicely when scrolling (or in some other inner-gameloop).
6330 midi_suspended = midissuspRESUME;
6331 currmidi = restore_midi;
6332 midi_pos = paused_midi_pos;
6333 }
6334
6335 if(text) free(text);
6336 if(zmi) free(zmi);
6337 return D_O_K;
6338 }
6339
6340 int32_t onAbout()
6341 {
6342 char buf1[80]={0};
6343 std::ostringstream oss;
6344 sprintf(buf1,"ZQuest Classic Player");
6345 oss << buf1 << '\n';
6346 sprintf(buf1,"Version: %s", getVersionString());
6347 oss << buf1 << '\n';
6348 sprintf(buf1,"Build Date: %s %s, %d at @ %s %s", dayextension(BUILDTM_DAY).c_str(), (char*)months[BUILDTM_MONTH], BUILDTM_YEAR, __TIME__, __TIMEZONE__);
6349 oss << buf1 << '\n';
6350
6351 InfoDialog("About ZC", oss.str()).show();
6352 return D_O_K;
6353 }
6354
6355 int32_t onQuest()
6356 {
6357 char fname[100];
6358 strcpy(fname, get_filename(qstpath));
6359 quest_dlg[0].dp2=get_zc_font(font_lfont);
6360 quest_dlg[1].dp = fname;
6361
6362 if(QHeader.quest_number==0)
6363 sprintf(str_a,"Custom");
6364 else
6365 sprintf(str_a,"%d",QHeader.quest_number);
6366
6367 sprintf(str_s,"%s",QHeader.getVerStr());
6368
6369 quest_dlg[11].d1 = quest_dlg[9].d1 = 0;
6370 quest_dlg[11].d2 = quest_dlg[9].d2 = 0;
6371
6372 large_dialog(quest_dlg);
6373
6374 do_zqdialog(quest_dlg, 0);
6375 return D_O_K;
6376 }
6377
6378 void call_vidmode_dlg();
6379 int32_t onVidMode()
6380 {
6381 call_vidmode_dlg();
6382 return D_O_K;
6383 }
6384
6385 #define addToHash(c,b,h) if(h->find(c ## key) == h->end()) \
6386 {(*h)[c ## key]=true;} else { if ( c ## key != 0 ) b = false;}
6387 //Added an extra statement, so that if the key is cleared to 0, the cleared
6388 //keybinding status need not be unique. -Z ( 1st April, 2019 )
6389
6390 void load_ukeys(int32_t* arr)
6391 {
6392 arr[ukey_a] = Akey;
6393 arr[ukey_b] = Bkey;
6394 arr[ukey_s] = Skey;
6395 arr[ukey_l] = Lkey;
6396 arr[ukey_r] = Rkey;
6397 arr[ukey_p] = Pkey;
6398 arr[ukey_ex1] = Exkey1;
6399 arr[ukey_ex2] = Exkey2;
6400 arr[ukey_ex3] = Exkey3;
6401 arr[ukey_ex4] = Exkey4;
6402 arr[ukey_du] = DUkey;
6403 arr[ukey_dd] = DDkey;
6404 arr[ukey_dl] = DLkey;
6405 arr[ukey_dr] = DRkey;
6406 arr[ukey_mod1a] = cheat_modifier_keys[0];
6407 arr[ukey_mod1b] = cheat_modifier_keys[1];
6408 arr[ukey_mod2a] = cheat_modifier_keys[2];
6409 arr[ukey_mod2b] = cheat_modifier_keys[3];
6410 };
6411
6412 static const char* ukey_names[] = {
6413 "A", "B", "Start", "L", "R", "Map",
6414 "Ex1", "Ex2", "Ex3", "Ex4", "Up", "Down",
6415 "Left", "Right", "Cheat Mod L1", "Cheat Mod L2",
6416 "Cheat Mod R1", "Cheat Mod R2",
6417 };
6418 std::string get_ukey_name(int32_t k)
6419 {
6420 if (k < num_ukey) return ukey_names[k];
6421 return "";
6422 }
6423
6424 int32_t onKeyboard()
6425 {
6426 int32_t a = Akey;
6427 int32_t b = Bkey;
6428 int32_t s = Skey;
6429 int32_t l = Lkey;
6430 int32_t r = Rkey;
6431 int32_t p = Pkey;
6432 int32_t ex1 = Exkey1;
6433 int32_t ex2 = Exkey2;
6434 int32_t ex3 = Exkey3;
6435 int32_t ex4 = Exkey4;
6436 int32_t du = DUkey;
6437 int32_t dd = DDkey;
6438 int32_t dl = DLkey;
6439 int32_t dr = DRkey;
6440 int32_t mod1a = cheat_modifier_keys[0];
6441 int32_t mod1b = cheat_modifier_keys[1];
6442 int32_t mod2a = cheat_modifier_keys[2];
6443 int32_t mod2b = cheat_modifier_keys[3];
6444 bool done=false;
6445 int32_t ret;
6446
6447 keyboard_control_dlg[0].dp2=get_zc_font(font_lfont);
6448
6449 large_dialog(keyboard_control_dlg);
6450
6451 while(!done)
6452 {
6453 ret = do_zqdialog(keyboard_control_dlg,3);
6454
6455 if(ret==3) // OK
6456 {
6457 int32_t ukeys[num_ukey];
6458 load_ukeys(ukeys);
6459 std::vector<std::string> uniqueError;
6460 for(int32_t q = 0; q < num_ukey; ++q)
6461 {
6462 for(int32_t p = q+1; p < num_ukey; ++p)
6463 {
6464 if(ukeys[q] == ukeys[p] && ukeys[q] != 0)
6465 {
6466 char buf[64];
6467 sprintf(buf, "'%s' conflicts with '%s'", get_ukey_name(q).c_str(), get_ukey_name(p).c_str());
6468 std::string str(buf);
6469 uniqueError.push_back(str);
6470 }
6471 }
6472 }
6473 if(uniqueError.size() == 0)
6474 {
6475 done = true;
6476 save_control_configs(true);
6477 }
6478 else
6479 {
6480 box_start(1, "Duplicate Keys", get_zc_font(font_lfont), get_zc_font(font_sfont), false, keyboard_control_dlg[0].w,keyboard_control_dlg[0].h, 2);
6481 box_out("Cannot have duplicate keybinds!"); box_eol();
6482 for(std::vector<std::string>::iterator it = uniqueError.begin();
6483 it != uniqueError.end(); ++it)
6484 {
6485 box_out((*it).c_str()); box_eol();
6486 }
6487 box_end(true);
6488 }
6489 }
6490 else // Cancel
6491 {
6492 Akey = a;
6493 Bkey = b;
6494 Skey = s;
6495 Lkey = l;
6496 Rkey = r;
6497 Pkey = p;
6498 Exkey1 = ex1;
6499 Exkey2 = ex2;
6500 Exkey3 = ex3;
6501 Exkey4 = ex4;
6502 DUkey = du;
6503 DDkey = dd;
6504 DLkey = dl;
6505 DRkey = dr;
6506 cheat_modifier_keys[0] = mod1a;
6507 cheat_modifier_keys[1] = mod1b;
6508 cheat_modifier_keys[2] = mod2a;
6509 cheat_modifier_keys[3] = mod2b;
6510
6511 done=true;
6512 }
6513
6514 rest(1);
6515 }
6516
6517 return D_O_K;
6518 }
6519
6520 int32_t onGamepad()
6521 {
6522 if (al_get_num_joysticks() == 0)
6523 {
6524 InfoDialog("ZC", "No gamepads detected.").show();
6525 return D_O_K;
6526 }
6527
6528 int32_t a = Abtn;
6529 int32_t b = Bbtn;
6530 int32_t s = Sbtn;
6531 int32_t l = Lbtn;
6532 int32_t r = Rbtn;
6533 int32_t m = Mbtn;
6534 int32_t p = Pbtn;
6535 int32_t ex1 = Exbtn1;
6536 int32_t ex2 = Exbtn2;
6537 int32_t ex3 = Exbtn3;
6538 int32_t ex4 = Exbtn4;
6539 int32_t up = DUbtn;
6540 int32_t down = DDbtn;
6541 int32_t left = DLbtn;
6542 int32_t right = DRbtn;
6543 int32_t joy = joystick_index;
6544 int32_t stick_1 = js_stick_1_x_stick;
6545 int32_t stick_2 = js_stick_2_x_stick;
6546
6547 gamepad_dlg[0].dp2=get_zc_font(font_lfont);
6548 if(analog_movement)
6549 gamepad_dlg[56].flags|=D_SELECTED;
6550 else
6551 gamepad_dlg[56].flags&=~D_SELECTED;
6552
6553 // TODO: should use controller device GUID or name instead of index, otherwise this value is not
6554 // consistent unless exact same number of joysticks is always connected. Name is problematic b/c
6555 // xinput driver doesn't actually get a name (at least, doesn't for my Xbox controller).
6556 // TODO: should store gamepad control mappings per-controller, otherwise switching joystick
6557 // requires remapping every time.
6558 if (joystick_index >= al_get_num_joysticks())
6559 joystick_index = 0;
6560 gamepad_dlg[61].d2 = joystick_index;
6561
6562 gamepad_dlg_cur_joystick = al_get_joystick(joystick_index);
6563 if (!gamepad_dlg_cur_joystick)
6564 {
6565 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
6566 return D_CLOSE;
6567 }
6568
6569 large_dialog(gamepad_dlg);
6570
6571 int32_t ret = do_zqdialog(gamepad_dlg,4);
6572
6573 if(ret == 4) //OK
6574 {
6575 analog_movement = gamepad_dlg[56].flags&D_SELECTED;
6576 joystick_index = gamepad_dlg[61].d2;
6577 gamepad_dlg_cur_joystick = al_get_joystick(joystick_index);
6578 if (!gamepad_dlg_cur_joystick)
6579 {
6580 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
6581 return D_CLOSE;
6582 }
6583 js_stick_1_y_stick = js_stick_1_x_stick;
6584 js_stick_2_y_stick = js_stick_2_x_stick;
6585 save_control_configs(false);
6586 }
6587 else //Cancel
6588 {
6589 Abtn = a;
6590 Bbtn = b;
6591 Sbtn = s;
6592 Lbtn = l;
6593 Rbtn = r;
6594 Mbtn = m;
6595 Pbtn = p;
6596 Exbtn1 = ex1;
6597 Exbtn2 = ex2;
6598 Exbtn3 = ex3;
6599 Exbtn4 = ex4;
6600 DUbtn = up;
6601 DDbtn = down;
6602 DLbtn = left;
6603 DRbtn = right;
6604 joystick_index = joy;
6605 js_stick_1_x_stick = stick_1;
6606 js_stick_2_x_stick = stick_2;
6607 }
6608
6609 return D_O_K;
6610 }
6611
6612 int32_t onCheatKeys()
6613 {
6614 int32_t oldcheats[Cheat::Last][2];
6615 memcpy(oldcheats, cheatkeys, sizeof(cheatkeys));
6616
6617 bool done=false;
6618
6619 while(!done)
6620 {
6621 bool confirm = false;
6622 CheatKeysDialog(&confirm).show();
6623 if(confirm) // OK
6624 {
6625 std::vector<std::string> uniqueError;
6626 char buf[512];
6627 for(size_t q = 1; q < Cheat::Last; ++q)
6628 {
6629 if(cheatkeys[q][1] && !cheatkeys[q][0])
6630 {
6631 cheatkeys[q][0] = cheatkeys[q][1];
6632 cheatkeys[q][1] = 0;
6633 }
6634 }
6635 for(size_t q = 1; q < Cheat::Last; ++q)
6636 {
6637 if(!bindable_cheat((Cheat)q)) continue;
6638 for(size_t p = q+1; p < Cheat::Last; ++p)
6639 {
6640 if(!bindable_cheat((Cheat)p)) continue;
6641 for(size_t q2 = 0; q2 <= 1; ++q2)
6642 for(size_t p2 = 0; p2 <= 1; ++p2)
6643 {
6644 if(cheatkeys[q][q2] == cheatkeys[p][p2] && cheatkeys[q][q2] != 0)
6645 {
6646 uniqueError.push_back(fmt::format("'{}' ({}) conflicts with '{}' ({}) - both '{}'",
6647 cheat_to_string((Cheat)q), q2?"Alt":"Main",
6648 cheat_to_string((Cheat)p), p2?"Alt":"Main",
6649 get_keystr(cheatkeys[q][q2])));
6650 }
6651 }
6652 }
6653 }
6654 if(uniqueError.size() == 0)
6655 {
6656 done = true;
6657 save_cheatkeys();
6658 }
6659 else
6660 {
6661 box_start(1, "Duplicate Keys", get_zc_font(font_lfont), get_zc_font(font_sfont), false, 500,400, 2);
6662 box_out("Cannot have duplicate keybinds!"); box_eol();
6663 for(std::vector<std::string>::iterator it = uniqueError.begin();
6664 it != uniqueError.end(); ++it)
6665 {
6666 box_out((*it).c_str()); box_eol();
6667 }
6668 box_end(true);
6669 }
6670 }
6671 else // Cancel
6672 {
6673 memcpy(cheatkeys, oldcheats, sizeof(cheatkeys));
6674 done=true;
6675 }
6676 rest(1);
6677 }
6678
6679 return D_O_K;
6680 }
6681
6682 int32_t onSound()
6683 {
6684 if (get_qr(qr_OLD_SCRIPT_VOLUME))
6685 {
6686 if (FFCore.coreflags & FFCORE_SCRIPTED_MIDI_VOLUME)
6687 {
6688 master_volume(-1, ((int32_t)FFCore.usr_midi_volume));
6689 }
6690 if (FFCore.coreflags & FFCORE_SCRIPTED_DIGI_VOLUME)
6691 {
6692 master_volume((int32_t)(FFCore.usr_digi_volume), 1);
6693 }
6694 if (FFCore.coreflags & FFCORE_SCRIPTED_MUSIC_VOLUME)
6695 {
6696 emusic_volume = (int32_t)FFCore.usr_music_volume;
6697 }
6698 if (FFCore.coreflags & FFCORE_SCRIPTED_SFX_VOLUME)
6699 {
6700 sfx_volume = (int32_t)FFCore.usr_sfx_volume;
6701 }
6702 }
6703 if ( FFCore.coreflags&FFCORE_SCRIPTED_PANSTYLE )
6704 {
6705 pan_style = (int32_t)FFCore.usr_panstyle;
6706 }
6707
6708 int32_t m = midi_volume;
6709 int32_t e = emusic_volume;
6710 int32_t s = sfx_volume;
6711 int32_t p = pan_style;
6712 pan_style = vbound(pan_style,0,3);
6713
6714 sound_dlg[0].dp2=get_zc_font(font_lfont);
6715
6716 large_dialog(sound_dlg);
6717
6718 midi_dp[1] = sound_dlg[6].x;
6719 midi_dp[2] = sound_dlg[6].y;
6720 emus_dp[1] = sound_dlg[8].x;
6721 emus_dp[2] = sound_dlg[8].y;
6722 sfx_dp[1] = sound_dlg[10].x;
6723 sfx_dp[2] = sound_dlg[10].y;
6724 pan_dp[1] = sound_dlg[11].x;
6725 pan_dp[2] = sound_dlg[11].y;
6726 sound_dlg[15].d2 = (midi_volume==255) ? 32 : midi_volume>>3;
6727 sound_dlg[17].d2 = (emusic_volume==255) ? 32 : emusic_volume>>3;
6728 sound_dlg[19].d2 = (sfx_volume==255) ? 32 : sfx_volume>>3;
6729 sound_dlg[20].d2 = pan_style;
6730
6731 int32_t ret = do_zqdialog(sound_dlg,1);
6732
6733 if(ret==2)
6734 {
6735 master_volume(digi_volume,midi_volume);
6736 if (zcmusic)
6737 zcmusic_set_volume(zcmusic, emusic_volume);
6738
6739 int32_t temp_volume = sfx_volume;
6740 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
6741 temp_volume = (sfx_volume * FFCore.usr_sfx_volume) / 10000 / 100;
6742 for(int32_t i=0; i<WAV_COUNT; ++i)
6743 {
6744 if(sfx_voice[i] >= 0)
6745 voice_set_volume(sfx_voice[i], temp_volume);
6746 }
6747 zc_set_config(sfx_sect,"midi",midi_volume);
6748 zc_set_config(sfx_sect,"sfx",sfx_volume);
6749 zc_set_config(sfx_sect,"emusic",emusic_volume);
6750 zc_set_config(sfx_sect,"pan",pan_style);
6751 }
6752 else
6753 {
6754 midi_volume = m;
6755 emusic_volume = e;
6756 sfx_volume = s;
6757 pan_style = p;
6758 }
6759
6760 return D_O_K;
6761 }
6762
6763 int32_t queding(char const* s1, char const* s2, char const* s3)
6764 {
6765 return jwin_alert("ZQuest Classic",s1,s2,s3,"&Yes","&No",'y','n',get_zc_font(font_lfont));
6766 }
6767
6768 int32_t onQuit()
6769 {
6770 if(Playing)
6771 {
6772 int32_t ret=0;
6773
6774 if(get_qr(qr_NOCONTINUE))
6775 {
6776 if(standalone_mode)
6777 {
6778 ret=queding("End current game?",
6779 "The continue screen is disabled; the game",
6780 "will be reloaded from the last save.");
6781 }
6782 else
6783 {
6784 ret=queding("End current game?",
6785 "The continue screen is disabled. You will",
6786 "be returned to the file select screen.");
6787 }
6788 }
6789 else
6790 ret=queding("End current game?",NULL,NULL);
6791
6792 if(ret==1)
6793 {
6794 disableClickToFreeze=false;
6795 Quit=qQUIT;
6796
6797 // Trying to evade a door repair charge?
6798 if(repaircharge)
6799 {
6800 game->change_drupy(-repaircharge);
6801 repaircharge=0;
6802 }
6803
6804 return D_CLOSE;
6805 }
6806 }
6807
6808 return D_O_K;
6809 }
6810
6811 int32_t onTryQuitMenu()
6812 {
6813 return onTryQuit(true);
6814 }
6815
6816 int32_t onTryQuit(bool inMenu)
6817 {
6818 if(Playing && !(GameFlags & GAMEFLAG_NO_F6))
6819 {
6820 if(active_cutscene.can_f6())
6821 {
6822 if(get_qr(qr_OLD_F6))
6823 {
6824 if(inMenu) onQuit();
6825 else /*if(!get_qr(qr_NOCONTINUE))*/ f_Quit(qQUIT);
6826 }
6827 else
6828 {
6829 disableClickToFreeze=false;
6830 GameFlags |= GAMEFLAG_TRYQUIT;
6831 }
6832 return D_CLOSE;
6833 }
6834 else active_cutscene.error();
6835 }
6836
6837 return D_O_K;
6838 }
6839
6840 int32_t onReset()
6841 {
6842 if(queding(" Reset system? ",NULL,NULL)==1)
6843 {
6844 disableClickToFreeze=false;
6845 Quit=qRESET;
6846 replay_quit();
6847 return D_CLOSE;
6848 }
6849
6850 return D_O_K;
6851 }
6852
6853 int32_t onExit()
6854 {
6855 if(queding(" Quit ZQuest Classic? ",NULL,NULL)==1)
6856 {
6857 Quit=qEXIT;
6858 return D_CLOSE;
6859 }
6860
6861 return D_O_K;
6862 }
6863
6864 int32_t onDebug()
6865 {
6866 if(debug_enabled)
6867 set_debug(!get_debug());
6868 return D_O_K;
6869 }
6870
6871 int32_t onHeartBeep()
6872 {
6873 heart_beep=!heart_beep;
6874 zc_set_config(cfg_sect,"heart_beep",heart_beep);
6875 return D_O_K;
6876 }
6877
6878 int32_t onSaveIndicator()
6879 {
6880 use_save_indicator = use_save_indicator ? 0 : 1;
6881 zc_set_config(cfg_sect,"save_indicator",use_save_indicator);
6882 return D_O_K;
6883 }
6884
6885 int32_t onEpilepsy()
6886 {
6887 if(jwin_alert3(
6888 "Epilepsy Flash Reduction",
6889 "Enabling this will reduce the intensity of flashing and screen wave effects.",
6890 "Disabling this will restore standard flash and wavy behaviour.",
6891 "Proceed?",
6892 "&Yes",
6893 "&No",
6894 NULL,
6895 'y',
6896 'n',
6897 0,
6898 get_zc_font(font_lfont)) == 1)
6899 {
6900 epilepsyFlashReduction = epilepsyFlashReduction ? 0 : 1;
6901 zc_set_config(cfg_sect,"epilepsy_flash_reduction",epilepsyFlashReduction);
6902 }
6903 return D_O_K;
6904 }
6905
6906 bool rc = false;
6907
6908 static DIALOG getnum_dlg[] =
6909 {
6910 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
6911 { jwin_win_proc, 80, 80, 160, 72, vc(0), vc(11), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
6912 { jwin_text_proc, 104, 104+4, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Number:", NULL, NULL },
6913 { jwin_edit_proc, 168, 104, 48, 16, 0, 0, 0, 0, 6, 0, NULL, NULL, NULL },
6914 { jwin_button_proc, 90, 126, 61, 21, vc(0), vc(11), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6915 { jwin_button_proc, 170, 126, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6916 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6917 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6918 };
6919
6920 int32_t getnumber(const char *prompt,int32_t initialval)
6921 {
6922 char buf[20];
6923 sprintf(buf,"%d",initialval);
6924 getnum_dlg[0].dp=(void *)prompt;
6925 getnum_dlg[0].dp2=get_zc_font(font_lfont);
6926 getnum_dlg[2].dp=buf;
6927
6928 large_dialog(getnum_dlg);
6929
6930 if(do_zqdialog(getnum_dlg,2)==3)
6931 return atoi(buf);
6932
6933 return initialval;
6934 }
6935
6936 int32_t onLife()
6937 {
6938 int value = vbound(getnumber("Life",game->get_life()),1,game->get_maxlife());
6939 cheats_enqueue(Cheat::Life, value);
6940 return D_O_K;
6941 }
6942
6943 int32_t onHeartC()
6944 {
6945 int max_life = vbound(getnumber("Heart Containers",game->get_maxlife()/game->get_hp_per_heart()),1,4095) * game->get_hp_per_heart();
6946 int life = vbound(getnumber("Life",game->get_life()/game->get_hp_per_heart()),1,max_life/game->get_hp_per_heart())*game->get_hp_per_heart();
6947 cheats_enqueue(Cheat::MaxLife, max_life);
6948 cheats_enqueue(Cheat::Life, life);
6949 return D_O_K;
6950 }
6951
6952 int32_t onMagicC()
6953 {
6954 int max_magic = vbound(getnumber("Magic Containers",game->get_maxmagic()/game->get_mp_per_block()),0,2047) * game->get_mp_per_block();
6955 int magic = vbound(getnumber("Magic",game->get_magic()/game->get_mp_per_block()),0,max_magic/game->get_mp_per_block())*game->get_mp_per_block();
6956 cheats_enqueue(Cheat::MaxMagic, max_magic);
6957 cheats_enqueue(Cheat::Magic, magic);
6958 return D_O_K;
6959 }
6960
6961 int32_t onRupies()
6962 {
6963 int value = vbound(getnumber("Rupees",game->get_rupies()),0,game->get_maxcounter(1));
6964 cheats_enqueue(Cheat::Rupies, value);
6965 return D_O_K;
6966 }
6967
6968 int32_t onMaxBombs()
6969 {
6970 int value = vbound(getnumber("Max Bombs",game->get_maxbombs()),0,0xFFFF);
6971 cheats_enqueue(Cheat::MaxBombs, value);
6972 cheats_enqueue(Cheat::Bombs, value);
6973 return D_O_K;
6974 }
6975
6976 int32_t onRefillLife()
6977 {
6978 cheats_enqueue(Cheat::Life, game->get_maxlife());
6979 return D_O_K;
6980 }
6981 int32_t onRefillMagic()
6982 {
6983 cheats_enqueue(Cheat::Magic, game->get_maxmagic());
6984 return D_O_K;
6985 }
6986 int32_t onClock()
6987 {
6988 cheats_enqueue(Cheat::Clock);
6989 return D_O_K;
6990 }
6991
6992 int32_t onQstPath()
6993 {
6994 char initial_path[2048];
6995 chop_path(qstdir);
6996 strcpy(initial_path, qstdir);
6997
6998 if (auto result = prompt_for_existing_folder("Quest File Directory", initial_path, "qst"))
6999 {
7000 char* path = result->data();
7001 chop_path(path);
7002 fix_filename_case(path);
7003 fix_filename_slashes(path);
7004 strcpy(qstdir,path);
7005 strcpy(qstpath,qstdir);
7006 zc_set_config("zeldadx","quest_dir",qstdir);
7007 flush_config_file();
7008 }
7009
7010 return D_O_K;
7011 }
7012
7013 #include "dialog/cheat_dialog.h"
7014 int32_t onCheat()
7015 {
7016 call_setcheat_dialog();
7017 game->set_cheat(maxcheat);
7018 if(cheat) game->did_cheat(true);
7019 return D_O_K;
7020 }
7021
7022 int32_t onCheatRupies()
7023 {
7024 cheats_enqueue(Cheat::Rupies, game->get_maxcounter(1));
7025 return D_O_K;
7026 }
7027
7028 int32_t onCheatArrows()
7029 {
7030 cheats_enqueue(Cheat::Arrows, game->get_maxarrows());
7031 return D_O_K;
7032 }
7033
7034 int32_t onCheatBombs()
7035 {
7036 cheats_enqueue(Cheat::Bombs, game->get_maxbombs(), game->get_maxcounter(6));
7037 return D_O_K;
7038 }
7039
7040 // *** screen saver
7041
7042 18524436 int32_t after_time()
7043 {
7044
1/2
✓ Branch 0 taken 18524436 times.
✗ Branch 1 not taken.
18524436 if(ss_enable == 0)
7045 return INT_MAX;
7046
7047
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18524436 times.
18524436 if(ss_after <= 0)
7048 return 5 * 60;
7049
7050
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18524436 times.
18524436 if(ss_after <= 3)
7051 return ss_after * 15 * 60;
7052
7053
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18524436 times.
18524436 if(ss_after <= 13)
7054 return (ss_after - 3) * 60 * 60;
7055
7056 18524436 return MAX_IDLE + 1;
7057 18524436 }
7058
7059 static const char *after_str[15] =
7060 {
7061 " 5 sec", "15 sec", "30 sec", "45 sec", " 1 min", " 2 min", " 3 min",
7062 " 4 min", " 5 min", " 6 min", " 7 min", " 8 min", " 9 min", "10 min",
7063 "Never"
7064 };
7065
7066 const char *after_list(int32_t index, int32_t *list_size)
7067 {
7068 if(index < 0)
7069 {
7070 *list_size = 15;
7071 return NULL;
7072 }
7073
7074 return after_str[index];
7075 }
7076
7077 409 static ListData after__list(after_list, &font);
7078
7079 static DIALOG scrsaver_dlg[] =
7080 {
7081 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
7082 409 { jwin_win_proc, 32, 64, 256, 136, 0, 0, 0, D_EXIT, 0, 0, (void *) "Screen Saver Settings", NULL, NULL },
7083 409 { jwin_frame_proc, 42, 92, 236, 70, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
7084 409 { jwin_text_proc, 60, 104, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Run After", NULL, NULL },
7085 409 { jwin_text_proc, 60, 128, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Speed", NULL, NULL },
7086 409 { jwin_text_proc, 60, 144, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Density", NULL, NULL },
7087 409 { jwin_droplist_proc, 144, 100, 96, 16, 0, 0, 0, 0, 0, 0, (void *) &after__list, NULL, NULL },
7088 409 { jwin_slider_proc, 144, 128, 116, 8, vc(0), jwin_pal[jcBOX], 0, 0, 6, 0, NULL, NULL, NULL },
7089 409 { jwin_slider_proc, 144, 144, 116, 8, vc(0), jwin_pal[jcBOX], 0, 0, 6, 0, NULL, NULL, NULL },
7090 409 { jwin_button_proc, 42, 170, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
7091 409 { jwin_button_proc, 124, 170, 72, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Preview", NULL, NULL },
7092 409 { jwin_button_proc, 218, 170, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
7093 409 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
7094 409 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
7095 };
7096
7097 int32_t onScreenSaver()
7098 {
7099 scrsaver_dlg[0].dp2=get_zc_font(font_lfont);
7100 int32_t oldcfgs[3];
7101 scrsaver_dlg[5].d1 = scrsaver_dlg[5].d2 = oldcfgs[0] = ss_after;
7102 scrsaver_dlg[6].d2 = oldcfgs[1] = ss_speed;
7103 scrsaver_dlg[7].d2 = oldcfgs[2] = ss_density;
7104
7105 large_dialog(scrsaver_dlg);
7106
7107 int32_t ret = do_zqdialog(scrsaver_dlg,-1);
7108
7109 if(ret == 8 || ret == 9)
7110 {
7111 ss_after = scrsaver_dlg[5].d1;
7112 ss_speed = scrsaver_dlg[6].d2;
7113 ss_density = scrsaver_dlg[7].d2;
7114 if(oldcfgs[0] != ss_after)
7115 zc_set_config(cfg_sect,"ss_after",ss_after);
7116 if(oldcfgs[1] != ss_speed)
7117 zc_set_config(cfg_sect,"ss_speed",ss_speed);
7118 if(oldcfgs[2] != ss_density)
7119 zc_set_config(cfg_sect,"ss_density",ss_density);
7120 }
7121
7122 if(ret == 9)
7123 // preview Screen Saver
7124 {
7125 clear_keybuf();
7126 Matrix(ss_speed, ss_density, 30);
7127 system_pal(true);
7128 sys_mouse();
7129 }
7130
7131 return D_O_K;
7132 }
7133
7134 /***** Menus *****/
7135
7136 enum
7137 {
7138 MENUID_GAME_LOADQUEST,
7139 MENUID_GAME_ENDGAME,
7140 };
7141
1/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
409 static NewMenu game_menu
7142 3272 {
7143
3/6
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 409 times.
✗ Branch 5 not taken.
409 { "&Continue","ESC", onContinue },
7144
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 {},
7145
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "L&oad Quest...", onCustomGame, MENUID_GAME_LOADQUEST },
7146
3/6
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 409 times.
✗ Branch 5 not taken.
409 { "&End Game","F6", onTryQuitMenu, MENUID_GAME_ENDGAME },
7147
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 {},
7148 #ifdef __EMSCRIPTEN__
7149 { "&Reset","F7", onReset },
7150 #elif defined(ALLEGRO_MACOSX)
7151 { "&Reset","F7", onReset },
7152 { "&Quit","F8", onExit },
7153 #else
7154
3/6
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 409 times.
✗ Branch 5 not taken.
409 { "&Reset","F9", onReset },
7155
3/6
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 409 times.
✗ Branch 5 not taken.
409 { "&Quit","F10", onExit },
7156 #endif
7157 };
7158
7159
1/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
409 static NewMenu snapshot_format_menu
7160 2863 {
7161
4/8
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 409 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 409 times.
✗ Branch 7 not taken.
409 { "&BMP", std::bind(onSetSnapshotFormat, ssfmtBMP) },
7162
4/8
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 409 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 409 times.
✗ Branch 7 not taken.
409 { "&GIF", std::bind(onSetSnapshotFormat, ssfmtGIF) },
7163
4/8
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 409 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 409 times.
✗ Branch 7 not taken.
409 { "&JPG", std::bind(onSetSnapshotFormat, ssfmtJPG) },
7164
4/8
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 409 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 409 times.
✗ Branch 7 not taken.
409 { "&PNG", std::bind(onSetSnapshotFormat, ssfmtPNG) },
7165
4/8
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 409 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 409 times.
✗ Branch 7 not taken.
409 { "PC&X", std::bind(onSetSnapshotFormat, ssfmtPCX) },
7166
4/8
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 409 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 409 times.
✗ Branch 7 not taken.
409 { "&TGA", std::bind(onSetSnapshotFormat, ssfmtTGA) },
7167 };
7168
7169
1/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
409 static NewMenu bottom_8_pixels_menu
7170 1636 {
7171
4/8
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 409 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 409 times.
✗ Branch 7 not taken.
409 { "&Default (qst)", std::bind(onSetBottom8Pixels, 0) },
7172
4/8
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 409 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 409 times.
✗ Branch 7 not taken.
409 { "&On", std::bind(onSetBottom8Pixels, 1) },
7173
4/8
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 409 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 409 times.
✗ Branch 7 not taken.
409 { "&Off", std::bind(onSetBottom8Pixels, 2) },
7174 };
7175
7176
1/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
409 static NewMenu controls_menu
7177 1636 {
7178
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Key&board...", onKeyboard },
7179
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "&Gamepad...", onGamepad },
7180
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "&Cheat Keys...", onCheatKeys },
7181 };
7182
7183
1/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
409 static NewMenu name_entry_mode_menu
7184 1636 {
7185
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "&Keyboard", onKeyboardEntry },
7186
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "&Letter Grid", onLetterGridEntry },
7187
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "&Extended Letter Grid", onExtLetterGridEntry },
7188 };
7189
7190 static void set_controls_menu_active()
7191 {
7192
7193 }
7194
7195 enum
7196 {
7197 MENUID_WINDOW_LOCK_ASPECT,
7198 MENUID_WINDOW_LOCK_INTSCALE,
7199 MENUID_WINDOW_SAVE_SIZE,
7200 MENUID_WINDOW_SAVE_POS,
7201 MENUID_WINDOW_STRETCH,
7202 };
7203
1/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
409 static NewMenu window_menu
7204 2454 {
7205
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Lock Aspect Ratio", onDragAspect, MENUID_WINDOW_LOCK_ASPECT },
7206
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Lock Integer Scale", onIntegerScaling, MENUID_WINDOW_LOCK_INTSCALE },
7207
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Save Size Changes", onSaveDragResize, MENUID_WINDOW_SAVE_SIZE },
7208
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Save Position Changes", onWinPosSave, MENUID_WINDOW_SAVE_POS },
7209
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Stretch Game Area", onStretchGame, MENUID_WINDOW_STRETCH },
7210 };
7211 void call_zc_options_dlg();
7212 enum
7213 {
7214 MENUID_OPTIONS_PAUSE_BG,
7215 MENUID_OPTIONS_EPILEPSYPROT,
7216 MENUID_OPTIONS_SHOWBOTTOMPIXELS,
7217 };
7218
1/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
409 static NewMenu options_menu
7219 3272 {
7220
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Name &Entry Mode", &name_entry_mode_menu },
7221
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "S&napshot Format", &snapshot_format_menu },
7222
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "&Window Settings", &window_menu },
7223
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Epilepsy Flash Reduction", onEpilepsy, MENUID_OPTIONS_EPILEPSYPROT },
7224
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Pause In Background", onPauseInBackground, MENUID_OPTIONS_PAUSE_BG },
7225
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Show Bottom 8 Pixels", &bottom_8_pixels_menu, MENUID_OPTIONS_SHOWBOTTOMPIXELS },
7226
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "More Options", call_zc_options_dlg },
7227 };
7228 enum
7229 {
7230 MENUID_SETTINGS_CONTROLS,
7231 MENUID_SETTINGS_CAPFPS,
7232 MENUID_SETTINGS_SHOWFPS,
7233 MENUID_SETTINGS_SHOWTIME,
7234 MENUID_SETTINGS_CLICK_FREEZE,
7235 MENUID_SETTINGS_TRANSLAYERS,
7236 MENUID_SETTINGS_NESQUIT,
7237 MENUID_SETTINGS_VOLKEYS,
7238 MENUID_SETTINGS_HEARTBEEP,
7239 MENUID_SETTINGS_SAVEINDICATOR,
7240 MENUID_SETTINGS_DEBUG,
7241 };
7242
1/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
409 static NewMenu settings_menu
7243 6953 {
7244
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "&Sound...", onSound },
7245
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "C&ontrols", &controls_menu, MENUID_SETTINGS_CONTROLS },
7246
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 {},
7247
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Options", &options_menu },
7248
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 {},
7249
3/6
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 409 times.
✗ Branch 5 not taken.
409 { "&Cap FPS","F1", onThrottleFPS, MENUID_SETTINGS_CAPFPS },
7250
3/6
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 409 times.
✗ Branch 5 not taken.
409 { "Show &FPS","F2", onShowFPS, MENUID_SETTINGS_SHOWFPS },
7251
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Show &Time", onShowTime, MENUID_SETTINGS_SHOWTIME },
7252
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Click to Freeze", onClickToFreeze, MENUID_SETTINGS_CLICK_FREEZE },
7253
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Cont. &Heart Beep", onHeartBeep, MENUID_SETTINGS_HEARTBEEP },
7254
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Show Trans. &Layers", onTransLayers, MENUID_SETTINGS_TRANSLAYERS },
7255
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Up+A+B To &Quit", onNESquit, MENUID_SETTINGS_NESQUIT },
7256
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Volume &Keys", onVolKeys, MENUID_SETTINGS_VOLKEYS },
7257
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Sa&ve Indicator", onSaveIndicator, MENUID_SETTINGS_SAVEINDICATOR },
7258
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 {},
7259
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Debu&g", onDebug, MENUID_SETTINGS_DEBUG },
7260 };
7261
7262 enum
7263 {
7264 MENUID_MISC_FULLSCREEN,
7265 MENUID_MISC_VIDMODE,
7266 MENUID_MISC_QUEST_INFO,
7267 MENUID_MISC_QUEST_DIR,
7268 MENUID_MISC_CONSOLE,
7269 MENUID_MISC_CLEAR_CONSOLE_ON_LOAD,
7270 };
7271
1/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
409 static NewMenu misc_menu
7272 6135 {
7273
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "&About...", onAbout },
7274 // TODO: re-enable, but: 1) do not use a bitmap thing that is hard to update 2) update names and 3) don't use the Z-word.
7275 // { "&Credits...", onCredits },
7276
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "&Fullscreen", onFullscreenMenu, MENUID_MISC_FULLSCREEN },
7277
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "&Video Mode...", onVidMode, MENUID_MISC_VIDMODE },
7278
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 {},
7279
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "&Quest Info...", onQuest, MENUID_MISC_QUEST_INFO },
7280
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Quest &MIDI Info...", onMIDICredits },
7281
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Quest &Directory...", onQstPath, MENUID_MISC_QUEST_DIR },
7282
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 {},
7283
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Take &Snapshot F12", onSnapshot },
7284
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Sc&reen Saver...", onScreenSaver },
7285
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Save ZC Configuration", OnSaveZCConfig },
7286
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Show Console", onConsole, MENUID_MISC_CONSOLE },
7287
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Clear Console on Qst Load", onClrConsoleOnLoad, MENUID_MISC_CLEAR_CONSOLE_ON_LOAD },
7288
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Clear Directory Cache", OnnClearQuestDir },
7289 };
7290
7291 enum
7292 {
7293 MENUID_REFILL_ARROWS,
7294 };
7295
1/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
409 static NewMenu refill_menu
7296 2454 {
7297
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "&Life", onRefillLife },
7298
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "&Magic", onRefillMagic },
7299
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "&Bombs", onCheatBombs },
7300
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "&Rupees", onCheatRupies },
7301
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "&Arrows", onCheatArrows, MENUID_REFILL_ARROWS },
7302 };
7303
7304 enum
7305 {
7306 MENUID_SHOW_L0,
7307 MENUID_SHOW_L1,
7308 MENUID_SHOW_L2,
7309 MENUID_SHOW_L3,
7310 MENUID_SHOW_L4,
7311 MENUID_SHOW_L5,
7312 MENUID_SHOW_L6,
7313 MENUID_SHOW_OVER,
7314 MENUID_SHOW_PUSH,
7315 MENUID_SHOW_FFC,
7316 MENUID_SHOW_SPR,
7317 MENUID_SHOW_SCRIPTNAME,
7318 MENUID_SHOW_SOLIDITY,
7319 MENUID_SHOW_HITBOX,
7320 MENUID_SHOW_EFFECT,
7321 };
7322
1/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
409 static NewMenu show_menu
7323 7771 {
7324
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Combos", onShowLayer0, MENUID_SHOW_L0 },
7325
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Layer 1", onShowLayer1, MENUID_SHOW_L1 },
7326
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Layer 2", onShowLayer2, MENUID_SHOW_L2 },
7327
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Layer 3", onShowLayer3, MENUID_SHOW_L3 },
7328
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Layer 4", onShowLayer4, MENUID_SHOW_L4 },
7329
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Layer 5", onShowLayer5, MENUID_SHOW_L5 },
7330
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Layer 6", onShowLayer6, MENUID_SHOW_L6 },
7331
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Overhead Combos", onShowLayerO, MENUID_SHOW_OVER },
7332
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Push Blocks", onShowLayerP, MENUID_SHOW_PUSH },
7333
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Freeform Combos", onShowLayerF, MENUID_SHOW_FFC },
7334
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Sprites", onShowLayerS, MENUID_SHOW_SPR },
7335
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 {},
7336
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Current FFC Scripts", onShowFFScripts, MENUID_SHOW_SCRIPTNAME },
7337
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 {},
7338
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Walkability", onShowLayerW, MENUID_SHOW_SOLIDITY },
7339
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Hitboxes", onShowHitboxes, MENUID_SHOW_HITBOX },
7340
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Effects", onShowLayerE, MENUID_SHOW_EFFECT },
7341
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Info Opacity", onShowInfoOpacity },
7342 };
7343
7344 enum
7345 {
7346 MENUID_CHEAT_CHOP_L1,
7347 MENUID_CHEAT_CHOP_L2,
7348 MENUID_CHEAT_CHOP_L3,
7349 MENUID_CHEAT_CHOP_L4,
7350 MENUID_CHEAT_INVULN,
7351 MENUID_CHEAT_NOCLIP,
7352 MENUID_CHEAT_IGNORESV,
7353 MENUID_CHEAT_GOFAST,
7354 };
7355
1/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
409 static NewMenu cheat_menu
7356 6953 {
7357
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Set &Cheat", onCheat },
7358
1/2
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
409 { MENUID_CHEAT_CHOP_L1 },
7359
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Re&fill", &refill_menu },
7360
1/2
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
409 { MENUID_CHEAT_CHOP_L2 },
7361
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "&Invincible", onClock, MENUID_CHEAT_INVULN },
7362
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Ma&x Bombs...", onMaxBombs },
7363
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "&Heart Containers...", onHeartC },
7364
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "&Magic Containers...", onMagicC },
7365
1/2
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
409 { MENUID_CHEAT_CHOP_L3 },
7366
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "&Hero Data...", onCheatConsole },
7367
1/2
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
409 { MENUID_CHEAT_CHOP_L4 },
7368
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Walk Through &Walls", onNoWalls, MENUID_CHEAT_NOCLIP },
7369
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Hero Ignores Side&view", onIgnoreSideview, MENUID_CHEAT_IGNORESV },
7370
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "&Quick Movement", onGoFast, MENUID_CHEAT_GOFAST },
7371
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "&Kill All Enemies", onKillCheat },
7372
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Trigger &Secrets", onSecretsCheat },
7373
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Trigger Secrets Perm", onSecretsCheatPerm },
7374
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Show/Hide Layer", &show_menu },
7375
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "Toggle &Light", onLightSwitch },
7376
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "&Goto Location...", onGoTo },
7377 };
7378
7379 #if DEVLEVEL > 0
7380 int32_t devLogging();
7381 int32_t devDebug();
7382 int32_t devTimestmp();
7383 #if DEVLEVEL > 1
7384 int32_t setCheat();
7385 #endif //DEVLEVEL > 1
7386 enum
7387 {
7388 MENUID_DEV_LOGGING,
7389 MENUID_DEV_DEBUG,
7390 MENUID_DEV_TIMESTAMP,
7391 MENUID_DEV_SETCHEAT,
7392 };
7393 static NewMenu dev_menu
7394 {
7395 { "&Force Error Log", devLogging, MENUID_DEV_LOGGING },
7396 // { "&Extra Debug Log", devDebug, MENUID_DEV_DEBUG },
7397 { "&Timestamp Log", devTimestmp, MENUID_DEV_TIMESTAMP },
7398 #if DEVLEVEL > 1
7399 {},
7400 { "Set &Cheat", setCheat, MENUID_DEV_SETCHEAT },
7401 #endif //DEVLEVEL > 1
7402 };
7403 int32_t devLogging()
7404 {
7405 dev_logging = !dev_logging;
7406 dev_menu.select_uid(MENUID_DEV_LOGGING, dev_logging);
7407 return D_O_K;
7408 }
7409 // int32_t devDebug()
7410 // {
7411 // dev_debug = !dev_debug;
7412 // dev_menu.select_uid(MENUID_DEV_DEBUG, dev_debug);
7413 // dev_menu[dv_dbg].flags = dev_debug ? D_SELECTED : 0;
7414 // return D_O_K;
7415 // }
7416 int32_t devTimestmp()
7417 {
7418 dev_timestmp = !dev_timestmp;
7419 dev_menu.select_uid(MENUID_DEV_TIMESTAMP, dev_timestmp);
7420 return D_O_K;
7421 }
7422 #if DEVLEVEL > 1
7423 int32_t setCheat()
7424 {
7425 cheat = (vbound(getnumber("Cheat Level",cheat), 0, 4));
7426 return D_O_K;
7427 }
7428 #endif //DEVLEVEL > 1
7429 #endif //DEVLEVEL > 0
7430
7431 enum
7432 {
7433 MENUID_PLAYER_CHEAT,
7434 };
7435
1/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
409 TopMenu the_player_menu
7436 2454 {
7437
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "&Game", &game_menu },
7438
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "&Settings", &settings_menu },
7439
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "&Cheat", &cheat_menu, MENUID_PLAYER_CHEAT, true },
7440
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "&Replay", &replay_menu },
7441
2/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 409 times.
✗ Branch 3 not taken.
409 { "&ZC", &misc_menu },
7442 #if DEVLEVEL > 0
7443 { "&Dev", &dev_menu },
7444 #endif
7445 };
7446
7447 int32_t onPauseInBackground()
7448 {
7449 if(jwin_alert3(
7450 "Toggle Pause In Background",
7451 "This action will change whether ZC Player pauses when the window loses focus.",
7452 "",
7453 "Proceed?",
7454 "&Yes",
7455 "&No",
7456 NULL,
7457 'y',
7458 'n',
7459 0,
7460 get_zc_font(font_lfont)) == 1)
7461 {
7462 pause_in_background = pause_in_background ? 0 : 1;
7463 zc_set_config("zeldadx","pause_in_background", pause_in_background);
7464 int switch_type = pause_in_background ? SWITCH_PAUSE : SWITCH_BACKGROUND;
7465 set_display_switch_mode(fullscreen?SWITCH_BACKAMNESIA:switch_type);
7466 set_display_switch_callback(SWITCH_OUT, switch_out_callback);
7467 set_display_switch_callback(SWITCH_IN, switch_in_callback);
7468 }
7469 options_menu.select_uid(MENUID_OPTIONS_PAUSE_BG, pause_in_background);
7470 return D_O_K;
7471 }
7472
7473 int32_t onKeyboardEntry()
7474 {
7475 NameEntryMode=0;
7476 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7477 return D_O_K;
7478 }
7479
7480 int32_t onLetterGridEntry()
7481 {
7482 NameEntryMode=1;
7483 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7484 return D_O_K;
7485 }
7486
7487 int32_t onExtLetterGridEntry()
7488 {
7489 NameEntryMode=2;
7490 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7491 return D_O_K;
7492 }
7493
7494 static BITMAP* oldscreen;
7495 int32_t onFullscreenMenu()
7496 {
7497 PALETTE oldpal;
7498 get_palette(oldpal);
7499
7500 fullscreen = !fullscreen;
7501 all_toggle_fullscreen(fullscreen);
7502 zc_set_config("zeldadx","fullscreen",fullscreen);
7503
7504 zc_set_palette(oldpal);
7505 gui_mouse_focus=0;
7506 extern int32_t switch_type;
7507 switch_type = pause_in_background ? SWITCH_PAUSE : SWITCH_BACKGROUND;
7508 set_display_switch_mode(fullscreen?SWITCH_BACKAMNESIA:switch_type);
7509 set_display_switch_callback(SWITCH_OUT, switch_out_callback);
7510 set_display_switch_callback(SWITCH_IN, switch_in_callback);
7511 misc_menu.select_uid(MENUID_MISC_FULLSCREEN, isFullScreen());
7512 misc_menu.select_uid(MENUID_MISC_VIDMODE, isFullScreen());
7513
7514 return D_O_K;
7515 }
7516
7517 312 void fix_menu()
7518 {
7519
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 312 times.
312 if(!debug_enabled)
7520 312 settings_menu.chop_index = 13;
7521 312 }
7522
7523 int32_t onSetSnapshotFormat(SnapshotType format)
7524 {
7525 SnapshotFormat = format;
7526 zc_set_config("zeldadx", "snapshot_format", format);
7527 snapshot_format_menu.select_only_index(format);
7528 return D_O_K;
7529 }
7530
7531 int32_t onSetBottom8Pixels(int option)
7532 {
7533 ShowBottomPixels = option;
7534 zc_set_config("zeldadx", "bottom_8_px", option);
7535 bottom_8_pixels_menu.select_only_index(option);
7536
7537 int qr = qr_HIDE_BOTTOM_8_PIXELS;
7538 bool value = false;
7539 if (option == 0)
7540 value = get_bit(quest_rules, qr) != 0; // This is the original value, as set in the qst file (or via scripting).
7541 else if (option == 1)
7542 value = false;
7543 else if (option == 2)
7544 value = true;
7545 enqueue_qr_change(qr, value);
7546
7547 return D_O_K;
7548 }
7549
7550 2915 void updateShowBottomPixels()
7551 {
7552 // It's too tricky the allow modifying the screen height between opening and closing the
7553 // active subscreen.
7554
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 2889 times.
2915 if (subscreen_open)
7555 26 return;
7556
7557
1/2
✓ Branch 0 taken 2889 times.
✗ Branch 1 not taken.
2889 if (!GameLoaded)
7558 show_bottom_8px = false;
7559 else
7560 2889 show_bottom_8px = !get_qr(qr_HIDE_BOTTOM_8_PIXELS);
7561
7562 2889 int target_bitmap_height = show_bottom_8px ? 232 : 224;
7563
2/2
✓ Branch 0 taken 2792 times.
✓ Branch 1 taken 97 times.
2889 if (framebuf->h != target_bitmap_height)
7564 {
7565 97 BITMAP* new_framebuf = create_bitmap_ex(8, 256, target_bitmap_height);
7566 97 clear_bitmap(new_framebuf);
7567 97 blit(framebuf, new_framebuf, 0, 0, 0, 0, new_framebuf->w, new_framebuf->h);
7568
7569 97 destroy_bitmap(framebuf);
7570 97 destroy_bitmap(script_menu_buf);
7571 97 destroy_bitmap(f6_menu_buf);
7572 97 destroy_bitmap(darkscr_bmp);
7573 97 destroy_bitmap(darkscr_bmp_trans);
7574
7575 97 framebuf = new_framebuf;
7576 97 script_menu_buf = create_bitmap_ex(8, 256, target_bitmap_height);
7577 97 f6_menu_buf = create_bitmap_ex(8, 256, target_bitmap_height);
7578 97 darkscr_bmp = create_bitmap_ex(8, 256, target_bitmap_height);
7579 97 darkscr_bmp_trans = create_bitmap_ex(8, 256, target_bitmap_height);
7580
7581 97 rti_game.a4_bitmap = framebuf;
7582 97 rti_game.set_size(framebuf->w, framebuf->h);
7583 97 al_set_new_bitmap_flags(ALLEGRO_CONVERT_BITMAP);
7584 97 al_destroy_bitmap(rti_game.bitmap);
7585 97 rti_game.bitmap = create_a5_bitmap(framebuf->w, framebuf->h);
7586 97 al_destroy_bitmap(rti_infolayer.bitmap);
7587 97 rti_infolayer.bitmap = create_a5_bitmap(framebuf->w, framebuf->h);
7588 97 rti_infolayer.set_size(framebuf->w, framebuf->h);
7589 97 }
7590 2915 }
7591
7592 void color_layer(RGB *src,RGB *dest,char r,char g,char b,char pos,int32_t from,int32_t to)
7593 {
7594 PALETTE tmp;
7595
7596 for(int32_t i=0; i<256; i++)
7597 {
7598 tmp[i].r=r;
7599 tmp[i].g=g;
7600 tmp[i].b=b;
7601 }
7602
7603 fade_interpolate(src,tmp,dest,pos,from,to);
7604 }
7605
7606 46 void system_pal(bool force)
7607 {
7608
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
46 if(is_sys_pal && !force) return;
7609 46 is_sys_pal = true;
7610 46 load_colorset(gui_colorset, syspal, jwin_a5_colors);
7611 46 hw_palette = &syspal;
7612 46 update_hw_pal = true;
7613 46 }
7614
7615 static uint32_t entered_sys_pal = 0;
7616 46 void enter_sys_pal()
7617 {
7618
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if(is_sys_pal)
7619 {
7620 if(entered_sys_pal)
7621 ++entered_sys_pal;
7622 return;
7623 }
7624 46 sys_mouse();
7625 46 system_pal(true);
7626 46 ++entered_sys_pal;
7627 46 }
7628 46 void exit_sys_pal()
7629 {
7630
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if(entered_sys_pal)
7631 {
7632
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 if(!--entered_sys_pal)
7633 {
7634 46 game_pal();
7635 46 game_mouse();
7636 46 }
7637 46 }
7638 46 }
7639
7640 void switch_out_callback()
7641 {
7642 if (pause_in_background && !MenuOpen)
7643 {
7644 System();
7645 }
7646 }
7647
7648 void switch_in_callback()
7649 {
7650 }
7651
7652 1149 void game_pal()
7653 {
7654 1149 is_sys_pal = false;
7655 1149 entered_sys_pal = 0;
7656 1149 hw_palette = &RAMpal;
7657 1149 update_hw_pal = true;
7658 1149 }
7659
7660 static char bar_str[] = "";
7661
7662 46 void music_pause()
7663 {
7664 //al_pause_duh(tmplayer);
7665 46 zcmusic_pause(zcmusic, ZCM_PAUSE);
7666
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if(zcmixer->oldtrack)
7667 zcmusic_pause(zcmixer->oldtrack, ZCM_PAUSE);
7668 46 zc_midi_pause();
7669 46 }
7670
7671 void music_resume()
7672 {
7673 //al_resume_duh(tmplayer);
7674 zcmusic_pause(zcmusic, ZCM_RESUME);
7675 if (zcmixer->oldtrack)
7676 zcmusic_pause(zcmixer->oldtrack, ZCM_RESUME);
7677 zc_midi_resume();
7678 }
7679
7680 7910 void music_stop()
7681 {
7682 //al_stop_duh(tmplayer);
7683 //unload_duh(tmusic);
7684 //tmusic=NULL;
7685 //tmplayer=NULL;
7686 7910 zcmusic_stop(zcmusic);
7687 7910 zcmusic_unload_file(zcmusic);
7688
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7910 times.
7910 if (zcmixer->oldtrack)
7689 {
7690 zcmusic_stop(zcmixer->oldtrack);
7691 zcmusic_unload_file(zcmixer->oldtrack);
7692 }
7693 7910 zcmixer->newtrack = NULL;
7694 7910 zc_stop_midi();
7695 7910 currmidi=-1;
7696 7910 }
7697
7698 bool reload_fonts = false;
7699 void System()
7700 {
7701 mouse_down = gui_mouse_b();
7702 music_pause();
7703 pause_all_sfx();
7704 MenuOpen = true;
7705 enter_sys_pal();
7706 // FONT *oldfont=font;
7707 // font=tfont;
7708
7709 misc_menu.select_uid(MENUID_MISC_FULLSCREEN, isFullScreen());
7710 misc_menu.disable_uid(MENUID_MISC_VIDMODE, isFullScreen());
7711
7712 #if DEVLEVEL > 1
7713 dev_menu.disable_uid(MENUID_DEV_SETCHEAT, !Playing);
7714 #endif
7715 game_menu.disable_uid(MENUID_GAME_LOADQUEST, get_unset_save_slot());
7716 game_menu.disable_uid(MENUID_GAME_ENDGAME, !Playing);
7717 misc_menu.disable_uid(MENUID_MISC_QUEST_INFO, !Playing);
7718 misc_menu.disable_uid(MENUID_MISC_QUEST_DIR, Playing);
7719 clear_keybuf();
7720
7721 clear_bitmap(menu_bmp);
7722 oldscreen = screen;
7723 screen = menu_bmp;
7724
7725 the_player_menu.reset_state();
7726 the_player_menu.position(0, 0);
7727
7728 bool running = true;
7729 bool esc = key[KEY_ESC] || cMbtn();
7730 bool autopop = esc;
7731 do
7732 {
7733 if(reload_fonts)
7734 {
7735 init_custom_fonts();
7736 clear_bitmap(menu_bmp);
7737 broadcast_dialog_message(MSG_DRAW, 0);
7738 reload_fonts = false;
7739 }
7740 if(handle_close_btn_quit())
7741 break;
7742
7743 //update submenus
7744 {
7745 settings_menu.disable_uid(MENUID_SETTINGS_CONTROLS, replay_is_replaying());
7746 settings_menu.select_uid(MENUID_SETTINGS_CAPFPS, Throttlefps);
7747 settings_menu.select_uid(MENUID_SETTINGS_SHOWFPS, ShowFPS);
7748 settings_menu.select_uid(MENUID_SETTINGS_SHOWTIME, ShowGameTime);
7749 settings_menu.select_uid(MENUID_SETTINGS_CLICK_FREEZE, ClickToFreeze);
7750 settings_menu.select_uid(MENUID_SETTINGS_TRANSLAYERS, TransLayers);
7751 settings_menu.select_uid(MENUID_SETTINGS_NESQUIT, NESquit);
7752 settings_menu.select_uid(MENUID_SETTINGS_VOLKEYS, volkeys);
7753
7754 window_menu.select_uid(MENUID_WINDOW_LOCK_ASPECT, DragAspect);
7755 window_menu.select_uid(MENUID_WINDOW_LOCK_INTSCALE, scaleForceInteger);
7756 window_menu.select_uid(MENUID_WINDOW_SAVE_SIZE, SaveDragResize);
7757 window_menu.select_uid(MENUID_WINDOW_SAVE_POS, SaveWinPos);
7758 window_menu.select_uid(MENUID_WINDOW_STRETCH, stretchGame);
7759
7760 options_menu.select_uid(MENUID_OPTIONS_EPILEPSYPROT, epilepsyFlashReduction);
7761 options_menu.select_uid(MENUID_OPTIONS_PAUSE_BG, pause_in_background);
7762 options_menu.disable_uid(MENUID_OPTIONS_SHOWBOTTOMPIXELS, replay_is_replaying());
7763
7764 name_entry_mode_menu.select_only_index(NameEntryMode);
7765
7766 misc_menu.select_uid(MENUID_MISC_CONSOLE, console_enabled);
7767 misc_menu.select_uid(MENUID_MISC_CLEAR_CONSOLE_ON_LOAD, clearConsoleOnLoad);
7768
7769 bool nocheat = (replay_is_replaying() || !Playing
7770 || (!maxcheat && !zcheats.flags && !get_debug() && DEVLEVEL < 2 && !zqtesting_mode && !devpwd()));
7771 the_player_menu.disable_uid(MENUID_PLAYER_CHEAT, nocheat);
7772 refill_menu.disable_uid(MENUID_REFILL_ARROWS, !get_qr(qr_TRUEARROWS));
7773 cheat_menu.chop_index.reset();
7774 if(cheat < 4)
7775 cheat_menu.chop_index = cheat_menu.ind_at(MENUID_CHEAT_CHOP_L1+cheat);
7776 cheat_menu.select_uid(MENUID_CHEAT_INVULN, getClock());
7777 cheat_menu.select_uid(MENUID_CHEAT_NOCLIP, toogam);
7778 cheat_menu.select_uid(MENUID_CHEAT_IGNORESV, ignoreSideview);
7779 cheat_menu.select_uid(MENUID_CHEAT_GOFAST, gofast);
7780
7781 show_menu.select_uid(MENUID_SHOW_L0, show_layers[0]);
7782 show_menu.select_uid(MENUID_SHOW_L1, show_layers[1]);
7783 show_menu.select_uid(MENUID_SHOW_L2, show_layers[2]);
7784 show_menu.select_uid(MENUID_SHOW_L3, show_layers[3]);
7785 show_menu.select_uid(MENUID_SHOW_L4, show_layers[4]);
7786 show_menu.select_uid(MENUID_SHOW_L5, show_layers[5]);
7787 show_menu.select_uid(MENUID_SHOW_L6, show_layers[6]);
7788 show_menu.select_uid(MENUID_SHOW_OVER, show_layer_over);
7789 show_menu.select_uid(MENUID_SHOW_PUSH, show_layer_push);
7790 show_menu.select_uid(MENUID_SHOW_SPR, show_sprites);
7791 show_menu.select_uid(MENUID_SHOW_FFC, show_ffcs);
7792 show_menu.select_uid(MENUID_SHOW_SOLIDITY, show_walkflags);
7793 show_menu.select_uid(MENUID_SHOW_SCRIPTNAME, show_ff_scripts);
7794 show_menu.select_uid(MENUID_SHOW_HITBOX, show_hitboxes);
7795 show_menu.select_uid(MENUID_SHOW_EFFECT, show_effectflags);
7796
7797 settings_menu.select_uid(MENUID_SETTINGS_HEARTBEEP, heart_beep);
7798 settings_menu.select_uid(MENUID_SETTINGS_SAVEINDICATOR, use_save_indicator);
7799
7800 replay_menu.by_uid(MENUID_REPLAY_STOP)->text = fmt::format("Stop {}",
7801 replay_get_mode() == ReplayMode::Record ? "recording" : "replaying");
7802
7803 replay_menu.select_uid(MENUID_REPLAY_RECORDNEW, zc_get_config("zeldadx", "replay_new_saves", false));
7804 #ifdef HAS_CURL
7805 replay_menu.select_uid(MENUID_REPLAY_AUTOUPLOAD, replay_upload_auto_enabled());
7806 #endif
7807 replay_menu.disable_uid(MENUID_REPLAY_STOP, !replay_is_active());
7808 replay_menu.disable_uid(MENUID_REPLAY_SAVE, replay_get_mode() != ReplayMode::Record);
7809 replay_menu.select_uid(MENUID_REPLAY_SNAP_ALL, replay_is_snapshot_all_frames());
7810
7811 snapshot_format_menu.select_only_index(SnapshotFormat);
7812 bottom_8_pixels_menu.select_only_index(ShowBottomPixels);
7813 }
7814
7815 if(debug_enabled)
7816 settings_menu.select_uid(MENUID_SETTINGS_DEBUG, get_debug());
7817
7818 if(autopop)
7819 clear_keybuf();
7820 the_player_menu.run(true);
7821 if(autopop)
7822 {
7823 the_player_menu.pop_sub(0, &the_player_menu);
7824 the_player_menu.draw(screen, the_player_menu.hovered_ind());
7825 autopop = false;
7826 update_hw_screen();
7827 }
7828
7829 update_hw_screen();
7830
7831 auto mb = gui_mouse_b();
7832 if(XOR(mb, mouse_down))
7833 {
7834 if(!the_player_menu.has_mouse())
7835 if(mb)
7836 break;
7837 mouse_down = mb;
7838 }
7839
7840 if(input_idle(true) > after_time())
7841 // run Screeen Saver
7842 {
7843 // Screen saver enabled for now.
7844 clear_keybuf();
7845 Matrix(ss_speed, ss_density, 0);
7846 system_pal(true);
7847 sys_mouse();
7848 }
7849
7850 poll_keyboard();
7851 if(esc)
7852 {
7853 if(!key[KEY_ESC])
7854 esc = false;
7855 }
7856
7857 if(keypressed() && !CHECK_ALT) //System hotkeys
7858 {
7859 auto c = peekkey();
7860 bool eatkey = true;
7861 switch(c>>8)
7862 {
7863 //Spare keys used by the menu
7864 case KEY_UP:
7865 case KEY_DOWN:
7866 case KEY_LEFT:
7867 case KEY_RIGHT:
7868 eatkey = false;
7869 break;
7870 case KEY_F1:
7871 onThrottleFPS();
7872 break;
7873 case KEY_F2:
7874 onShowFPS();
7875 break;
7876 case KEY_F6:
7877 onTryQuitMenu();
7878 break;
7879 #ifndef ALLEGRO_MACOSX
7880 case KEY_F9:
7881 onReset();
7882 break;
7883 case KEY_F10:
7884 onExit();
7885 break;
7886 #else
7887 case KEY_F7:
7888 onReset();
7889 break;
7890 case KEY_F8:
7891 onExit();
7892 break;
7893 #endif
7894 case KEY_F12:
7895 onSnapshot();
7896 break;
7897 case KEY_TAB:
7898 onDebug();
7899 break;
7900 case KEY_ESC:
7901 if(!esc)
7902 running = false;
7903 break;
7904 }
7905 if(eatkey)
7906 readkey();
7907 }
7908 if(Quit || (GameFlags & GAMEFLAG_TRYQUIT))
7909 break;
7910 }
7911 while(running);
7912
7913 screen = oldscreen;
7914
7915 mouse_down=gui_mouse_b();
7916 MenuOpen = false;
7917 if(Quit)
7918 {
7919 kill_sfx();
7920 music_stop();
7921 update_hw_screen();
7922 }
7923 else
7924 {
7925 music_resume();
7926 resume_all_sfx();
7927
7928 if(rc)
7929 ringcolor(false);
7930 }
7931 exit_sys_pal();
7932
7933 eat_buttons();
7934
7935 rc=false;
7936 clear_keybuf();
7937
7938 zc_init_apply_cheat_delta();
7939 }
7940
7941 312 void fix_dialogs()
7942 {
7943 312 jwin_center_dialog(about_dlg);
7944 312 jwin_center_dialog(gamepad_dlg);
7945 312 jwin_center_dialog(credits_dlg);
7946 312 jwin_center_dialog(gamemode_dlg);
7947 312 jwin_center_dialog(getnum_dlg);
7948 312 jwin_center_dialog(goto_dlg);
7949 312 jwin_center_dialog(keyboard_control_dlg);
7950 312 jwin_center_dialog(midi_dlg);
7951 312 jwin_center_dialog(quest_dlg);
7952 312 jwin_center_dialog(scrsaver_dlg);
7953 312 jwin_center_dialog(sound_dlg);
7954 312 jwin_center_dialog(triforce_dlg);
7955 312 }
7956
7957 4328 INLINE int32_t mixvol(int32_t v1,int32_t v2)
7958 {
7959
3/4
✓ Branch 0 taken 4328 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4306 times.
✓ Branch 3 taken 22 times.
4328 return (zc_min(v1,255)*zc_min(v2,255)) >> 8;
7960 }
7961
7962 292 int32_t get_emusic_volume()
7963 {
7964 292 int32_t temp_volume = emusic_volume;
7965
2/4
✓ Branch 0 taken 292 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 292 times.
✗ Branch 3 not taken.
292 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
7966 temp_volume = (emusic_volume * FFCore.usr_music_volume) / 10000 / 100;
7967
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 292 times.
292 if (!zcmusic)
7968 292 return temp_volume;
7969 return (temp_volume * zcmusic->fadevolume) / 10000;
7970 292 }
7971
7972 int32_t get_zcmusicpos()
7973 {
7974 int32_t debugtracething = zcmusic_get_curpos(zcmusic);
7975 return debugtracething;
7976 return 0;
7977 }
7978
7979 void set_zcmusicpos(int32_t position)
7980 {
7981 zcmusic_set_curpos(zcmusic, position);
7982 }
7983
7984 void set_zcmusicspeed(int32_t speed)
7985 {
7986 zcmusic_set_speed(zcmusic, speed);
7987 }
7988
7989 int32_t get_zcmusiclen()
7990 {
7991 return zcmusic_get_length(zcmusic);
7992 }
7993
7994 3 void set_zcmusicloop(double start, double end)
7995 {
7996 3 zcmusic_set_loop(zcmusic, start, end);
7997 3 }
7998
7999 64164 void jukebox(int32_t index,int32_t loop)
8000 {
8001
1/2
✓ Branch 0 taken 64164 times.
✗ Branch 1 not taken.
64164 if (is_headless())
8002 64164 return;
8003
8004 music_stop();
8005
8006 if(index<0) index=MAXMIDIS-1;
8007
8008 if(index>=MAXMIDIS) index=0;
8009
8010 music_stop();
8011
8012 // Allegro's DIGMID driver (the one normally used on on Linux) gets
8013 // stuck notes when a song stops. This fixes it.
8014 if(strcmp(midi_driver->name, "DIGMID")==0)
8015 zc_set_volume(0, 0);
8016
8017 zc_set_volume(-1, mixvol(tunes[index].volume, midi_volume >>1));
8018 zc_play_midi(tunes[index].data,loop);
8019
8020 if(tunes[index].start>0)
8021 zc_midi_seek(tunes[index].start);
8022
8023 midi_loop_start = tunes[index].loop_start;
8024 midi_loop_end = tunes[index].loop_end;
8025
8026 currmidi=index;
8027 master_volume(digi_volume, midi_volume);
8028 //midi_paused=false;
8029 64164 }
8030
8031 64164 void jukebox(int32_t index)
8032 {
8033
1/2
✓ Branch 0 taken 64164 times.
✗ Branch 1 not taken.
64164 if(index<0) index=MAXMIDIS-1;
8034
8035
1/2
✓ Branch 0 taken 64164 times.
✗ Branch 1 not taken.
64164 if(index>=MAXMIDIS) index=0;
8036
8037 // do nothing if it's already playing
8038
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 64164 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
64164 if(index==currmidi && midi_pos>=0)
8039 {
8040 return;
8041 }
8042
8043 64164 jukebox(index,tunes[index].loop);
8044 64164 }
8045
8046 103 void play_DmapMusic()
8047 {
8048
1/2
✓ Branch 0 taken 103 times.
✗ Branch 1 not taken.
103 if (is_headless())
8049 103 return;
8050
8051 static char tfile[2048];
8052 static int32_t ttrack=0;
8053 bool domidi=false;
8054
8055 int32_t fadeoutframes = 0;
8056 if (zcmusic != NULL)
8057 fadeoutframes = zcmusic->fadeoutframes;
8058
8059 if(DMaps[cur_dmap].tmusic[0]!=0)
8060 {
8061 if(zcmusic==NULL ||
8062 strcmp(zcmusic->filename,DMaps[cur_dmap].tmusic)!=0 ||
8063 (zcmusic->type==ZCMF_GME && zcmusic->track != DMaps[cur_dmap].tmusictrack))
8064 {
8065 if (DMaps[cur_dmap].tmusic_xfade_in > 0 || fadeoutframes > 0)
8066 {
8067 if (play_enh_music_crossfade(DMaps[cur_dmap].tmusic, qstpath, DMaps[cur_dmap].tmusictrack, get_emusic_volume(), DMaps[cur_dmap].tmusic_xfade_in, fadeoutframes))
8068 {
8069 if (zcmusic != NULL)
8070 {
8071 zcmusic->fadeoutframes = DMaps[cur_dmap].tmusic_xfade_out;
8072 zcmusic_set_loop(zcmusic, double(DMaps[cur_dmap].tmusic_loop_start / 10000.0), double(DMaps[cur_dmap].tmusic_loop_end / 10000.0));
8073 }
8074 }
8075 }
8076 else
8077 {
8078 if (zcmusic != NULL)
8079 {
8080 zcmusic_stop(zcmusic);
8081 zcmusic_unload_file(zcmusic);
8082 zcmusic = NULL;
8083 zcmixer->newtrack = NULL;
8084 }
8085
8086 zcmusic = zcmusic_load_for_quest(DMaps[cur_dmap].tmusic, qstpath).first;
8087 zcmixer->newtrack = zcmusic;
8088
8089 if (zcmusic != NULL)
8090 {
8091 zc_stop_midi();
8092 strcpy(tfile, DMaps[cur_dmap].tmusic);
8093 zcmusic_play(zcmusic, emusic_volume);
8094 int32_t temptracks = 0;
8095 temptracks = zcmusic_get_tracks(zcmusic);
8096 temptracks = (temptracks < 2) ? 1 : temptracks;
8097 ttrack = vbound(DMaps[cur_dmap].tmusictrack, 0, temptracks - 1);
8098 zcmusic_change_track(zcmusic, ttrack);
8099 zcmusic_set_loop(zcmusic, double(DMaps[cur_dmap].tmusic_loop_start / 10000.0), double(DMaps[cur_dmap].tmusic_loop_end / 10000.0));
8100 }
8101 else
8102 {
8103 tfile[0] = 0;
8104 domidi = true;
8105 }
8106 }
8107 }
8108 }
8109 else
8110 {
8111 if (DMaps[cur_dmap].midi == 0 && fadeoutframes > 0 && zcmusic != NULL && strcmp(zcmusic->filename, DMaps[cur_dmap].tmusic) != 0)
8112 {
8113 play_enh_music_crossfade(NULL, qstpath, DMaps[cur_dmap].tmusictrack, get_emusic_volume(), DMaps[cur_dmap].tmusic_xfade_in, fadeoutframes);
8114 }
8115 else
8116 {
8117 domidi = true;
8118 }
8119 }
8120
8121 if(domidi)
8122 {
8123 int32_t m=DMaps[cur_dmap].midi;
8124
8125 switch(m)
8126 {
8127 case 1:
8128 jukebox(ZC_MIDI_OVERWORLD);
8129 break;
8130
8131 case 2:
8132 jukebox(ZC_MIDI_DUNGEON);
8133 break;
8134
8135 case 3:
8136 jukebox(ZC_MIDI_LEVEL9);
8137 break;
8138
8139 default:
8140 if(m>=4 && m<4+MAXCUSTOMMIDIS)
8141 jukebox(m+MIDIOFFSET_DMAP);
8142 else
8143 music_stop();
8144 }
8145 }
8146 103 }
8147
8148 35710 void playLevelMusic()
8149 {
8150
1/2
✓ Branch 0 taken 35710 times.
✗ Branch 1 not taken.
35710 if (is_headless())
8151 35710 return;
8152
8153 int32_t m=hero_scr->screen_midi;
8154
8155 switch(m)
8156 {
8157 case -2:
8158 music_stop();
8159 break;
8160
8161 case -1:
8162 play_DmapMusic();
8163 break;
8164
8165 case 1:
8166 jukebox(ZC_MIDI_OVERWORLD);
8167 break;
8168
8169 case 2:
8170 jukebox(ZC_MIDI_DUNGEON);
8171 break;
8172
8173 case 3:
8174 jukebox(ZC_MIDI_LEVEL9);
8175 break;
8176
8177 default:
8178 if(m>=4 && m<4+MAXCUSTOMMIDIS)
8179 jukebox(m+MIDIOFFSET_MAPSCR);
8180 else
8181 music_stop();
8182 }
8183 35710 }
8184
8185 4328 void master_volume(int32_t dv,int32_t mv)
8186 {
8187
7/8
✓ Branch 0 taken 2008 times.
✓ Branch 1 taken 2320 times.
✓ Branch 2 taken 1967 times.
✓ Branch 3 taken 353 times.
✓ Branch 4 taken 2320 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1967 times.
✓ Branch 7 taken 353 times.
4328 if(dv>=0) digi_volume=zc_max(zc_min(dv,255),0);
8188
8189
7/8
✓ Branch 0 taken 2004 times.
✓ Branch 1 taken 2324 times.
✓ Branch 2 taken 2000 times.
✓ Branch 3 taken 324 times.
✓ Branch 4 taken 2324 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2000 times.
✓ Branch 7 taken 324 times.
4328 if(mv>=0) midi_volume=zc_max(zc_min(mv,255),0);
8190
8191
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 4328 times.
✓ Branch 2 taken 4328 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4328 times.
4328 int32_t i = zc_min(zc_max(currmidi,0),MAXMIDIS-1);
8192 4328 int32_t temp_vol = midi_volume;
8193
2/2
✓ Branch 0 taken 4016 times.
✓ Branch 1 taken 312 times.
4328 if (!get_qr(qr_OLD_SCRIPT_VOLUME))
8194 312 temp_vol = (midi_volume * FFCore.usr_music_volume) / 10000 / 100;
8195 4328 zc_set_volume(digi_volume,mixvol(tunes[i].volume, temp_vol));
8196 4328 }
8197
8198 // array of voices, one for each sfx sample in the data file
8199 // 0+ = voice #
8200 // -1 = voice not allocated
8201 312 void Z_init_sound()
8202 {
8203
2/2
✓ Branch 0 taken 79872 times.
✓ Branch 1 taken 312 times.
80184 for(int32_t i=0; i<WAV_COUNT; i++)
8204 79872 sfx_voice[i]=-1;
8205
8206 312 const char* midis[ZC_MIDI_COUNT] = {
8207 "assets/dungeon.mid",
8208 "assets/ending.mid",
8209 "assets/gameover.mid",
8210 "assets/level9.mid",
8211 "assets/overworld.mid",
8212 "assets/title.mid",
8213 "assets/triforce.mid",
8214 };
8215
2/2
✓ Branch 0 taken 2184 times.
✓ Branch 1 taken 312 times.
2496 for(int32_t i=0; i<ZC_MIDI_COUNT; i++)
8216 {
8217 2184 tunes[i].data = load_midi(midis[i]);
8218
1/2
✓ Branch 0 taken 2184 times.
✗ Branch 1 not taken.
2184 if (!tunes[i].data)
8219 Z_error_fatal("Missing required file %s\n", midis[i]);
8220 2184 }
8221
8222
2/2
✓ Branch 0 taken 78624 times.
✓ Branch 1 taken 312 times.
78936 for(int32_t j=0; j<MAXCUSTOMMIDIS; j++)
8223 78624 tunes[ZC_MIDI_COUNT+j].data=NULL;
8224
8225 312 master_volume(digi_volume,midi_volume);
8226 312 }
8227
8228 // returns number of voices currently allocated
8229 int32_t sfx_count()
8230 {
8231 int32_t c=0;
8232
8233 for(int32_t i=0; i<WAV_COUNT; i++)
8234 if(sfx_voice[i]!=-1)
8235 ++c;
8236
8237 return c;
8238 }
8239
8240 // clean up finished samples
8241 18315828 void sfx_cleanup()
8242 {
8243
2/2
✓ Branch 0 taken 4688851968 times.
✓ Branch 1 taken 18315828 times.
4707167796 for(int32_t i=0; i<WAV_COUNT; i++)
8244
3/4
✓ Branch 0 taken 1267308 times.
✓ Branch 1 taken 4687584660 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1267308 times.
4690119276 if(sfx_voice[i]!=-1 && voice_get_position(sfx_voice[i])<0)
8245 {
8246 1267308 deallocate_voice(sfx_voice[i]);
8247 1267308 sfx_voice[i]=-1;
8248 1267308 }
8249 18315828 }
8250
8251 1267473 SAMPLE* sfx_get_sample(int32_t index)
8252 {
8253 // check index
8254
2/4
✓ Branch 0 taken 1267473 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1267473 times.
1267473 if (index<=0 || index>=WAV_COUNT)
8255 return nullptr;
8256
8257
2/2
✓ Branch 0 taken 446247 times.
✓ Branch 1 taken 821226 times.
1267473 if (sfxdat)
8258 {
8259
1/2
✓ Branch 0 taken 446247 times.
✗ Branch 1 not taken.
446247 if (index<Z35)
8260 {
8261 446247 return (SAMPLE*)sfxdata[index].dat;
8262 }
8263 else
8264 {
8265 return (SAMPLE*)sfxdata[Z35].dat;
8266 }
8267 }
8268 else
8269 {
8270 821226 return &customsfxdata[index];
8271 }
8272
8273 return nullptr;
8274 1267473 }
8275
8276 // allocates a voice for the sample "wav_index" (index into zelda.dat)
8277 // if a voice is already allocated (and/or playing), then it just returns true
8278 // Returns true: voice is allocated
8279 // false: unsuccessful
8280 1880888 bool sfx_init(int32_t index)
8281 {
8282 // check index
8283
3/4
✓ Branch 0 taken 1400226 times.
✓ Branch 1 taken 480662 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1400226 times.
1880888 if(index<=0 || index>=WAV_COUNT)
8284 480662 return false;
8285
8286
2/2
✓ Branch 0 taken 132813 times.
✓ Branch 1 taken 1267413 times.
1400226 if (sfx_voice[index] == -1)
8287 {
8288 1267413 SAMPLE* sample = sfx_get_sample(index);
8289
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1267413 times.
1267413 if (!sample)
8290 return false;
8291
8292 1267413 sfx_voice[index] = allocate_voice(sample);
8293 1267413 }
8294
8295 1400226 return sfx_voice[index] != -1;
8296 1880888 }
8297
8298 int32_t sfx_get_default_freq(int32_t index)
8299 {
8300 if (sfxdat)
8301 {
8302 if (index < Z35)
8303 {
8304 return ((SAMPLE*)sfxdata[index].dat)->freq;
8305 }
8306 else
8307 {
8308 return ((SAMPLE*)sfxdata[Z35].dat)->freq;
8309 }
8310 }
8311 else
8312 {
8313 return customsfxdata[index].freq;
8314 }
8315 }
8316
8317 int32_t sfx_get_length(int32_t index)
8318 {
8319 if (sfxdat)
8320 {
8321 if (index < Z35)
8322 {
8323 return int32_t(((SAMPLE*)sfxdata[index].dat)->len);
8324 }
8325 else
8326 {
8327 return int32_t(((SAMPLE*)sfxdata[Z35].dat)->len);
8328 }
8329 }
8330 else
8331 {
8332 return int32_t(customsfxdata[index].len);
8333 }
8334 }
8335
8336 // plays an sfx sample
8337 1880888 void sfx(int32_t index,int32_t pan,bool loop, bool restart, int32_t vol, int32_t freq)
8338 {
8339
2/2
✓ Branch 0 taken 1400226 times.
✓ Branch 1 taken 480662 times.
1880888 if(!sfx_init(index))
8340 480662 return;
8341
1/2
✓ Branch 0 taken 1400226 times.
✗ Branch 1 not taken.
1400226 if (!is_headless())
8342 {
8343 voice_set_playmode(sfx_voice[index], loop ? PLAYMODE_LOOP : PLAYMODE_PLAY);
8344 voice_set_pan(sfx_voice[index], pan);
8345
8346 // Only used by ZScript currently
8347 if (freq <= -1)
8348 {
8349 freq = sfx_get_default_freq(index);
8350 }
8351 voice_set_frequency(sfx_voice[index], freq);
8352
8353 // Only used by ZScript currently
8354 int32_t temp_volume = (sfx_volume * vol) / 10000 / 100;
8355 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
8356 temp_volume = (temp_volume * FFCore.usr_sfx_volume) / 10000 / 100;
8357 voice_set_volume(sfx_voice[index], temp_volume);
8358
8359 int32_t pos = voice_get_position(sfx_voice[index]);
8360
8361 if (restart) voice_set_position(sfx_voice[index], 0);
8362
8363 if (pos <= 0)
8364 voice_start(sfx_voice[index]);
8365 }
8366
8367
3/4
✓ Branch 0 taken 865791 times.
✓ Branch 1 taken 534435 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 865791 times.
1400226 if (restart && replay_is_debug())
8368 {
8369 // TODO(replays): get rid of this bandaid next time replays are mass-updated.
8370 865791 const char* sfx_name = sfx_string[index];
8371
2/2
✓ Branch 0 taken 853992 times.
✓ Branch 1 taken 11799 times.
865791 if (strcmp(sfx_name, "Hero is hit") == 0)
8372 11799 sfx_name = "Player is hit";
8373
2/2
✓ Branch 0 taken 853865 times.
✓ Branch 1 taken 127 times.
853992 else if (strcmp(sfx_name, "Hero dies") == 0)
8374 127 sfx_name = "Player dies";
8375
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 865791 times.
865791 replay_step_comment(fmt::format("sfx {}", sfx_name));
8376 865791 }
8377 1880888 }
8378
8379 // true if sfx is allocated
8380 203255 bool sfx_allocated(int32_t index)
8381 {
8382
3/4
✓ Branch 0 taken 33546 times.
✓ Branch 1 taken 169709 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 33546 times.
203255 return (index>0 && index<WAV_COUNT && sfx_voice[index]!=-1);
8383 }
8384
8385 // start it (in loop mode) if it's not already playing,
8386 // otherwise adjust it to play in loop mode -DD
8387 118485 void cont_sfx(int32_t index)
8388 {
8389
1/2
✓ Branch 0 taken 118485 times.
✗ Branch 1 not taken.
118485 if (is_headless())
8390 118485 return;
8391
8392 if(!sfx_init(index))
8393 {
8394 return;
8395 }
8396
8397 if(voice_get_position(sfx_voice[index])<=0)
8398 {
8399 voice_set_position(sfx_voice[index],0);
8400 voice_set_playmode(sfx_voice[index],PLAYMODE_LOOP);
8401 voice_set_volume(sfx_voice[index], sfx_volume);
8402 voice_start(sfx_voice[index]);
8403 }
8404 else
8405 {
8406 adjust_sfx(index, 128, true);
8407 }
8408 118485 }
8409
8410 // adjust parameters while playing
8411 4948 void adjust_sfx(int32_t index,int32_t pan,bool loop)
8412 {
8413
4/6
✓ Branch 0 taken 4511 times.
✓ Branch 1 taken 437 times.
✓ Branch 2 taken 4511 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4511 times.
4948 if(index<=0 || index>=WAV_COUNT || sfx_voice[index]==-1)
8414 4948 return;
8415
8416 voice_set_playmode(sfx_voice[index],loop?PLAYMODE_LOOP:PLAYMODE_PLAY);
8417 voice_set_pan(sfx_voice[index],pan);
8418 4948 }
8419
8420 // pauses a voice
8421 3254 void pause_sfx(int32_t index)
8422 {
8423
3/6
✓ Branch 0 taken 3254 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3254 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3254 times.
3254 if(index>0 && index<WAV_COUNT && sfx_voice[index]!=-1)
8424 voice_stop(sfx_voice[index]);
8425 3254 }
8426
8427 // resumes a voice
8428 1372 void resume_sfx(int32_t index)
8429 {
8430
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1372 times.
1372 if (is_headless())
8431 1372 return;
8432
8433 if(index>0 && index<WAV_COUNT && sfx_voice[index]!=-1)
8434 voice_start(sfx_voice[index]);
8435 1372 }
8436
8437 // pauses all active voices
8438 1063 void pause_all_sfx()
8439 {
8440
2/2
✓ Branch 0 taken 272128 times.
✓ Branch 1 taken 1063 times.
273191 for(int32_t i=0; i<WAV_COUNT; i++)
8441
2/2
✓ Branch 0 taken 272126 times.
✓ Branch 1 taken 2 times.
272130 if(sfx_voice[i]!=-1)
8442 2 voice_stop(sfx_voice[i]);
8443 1063 }
8444
8445 // resumes all paused voices
8446 1017 void resume_all_sfx()
8447 {
8448
2/2
✓ Branch 0 taken 260352 times.
✓ Branch 1 taken 1017 times.
261369 for(int32_t i=0; i<WAV_COUNT; i++)
8449
1/2
✓ Branch 0 taken 260352 times.
✗ Branch 1 not taken.
260352 if(sfx_voice[i]!=-1)
8450 voice_start(sfx_voice[i]);
8451 1017 }
8452
8453 // stops an sfx and deallocates the voice
8454 14623486 void stop_sfx(int32_t index)
8455 {
8456
3/4
✓ Branch 0 taken 14376440 times.
✓ Branch 1 taken 247046 times.
✓ Branch 2 taken 14376440 times.
✗ Branch 3 not taken.
14623486 if(index<=0 || index>=WAV_COUNT)
8457 247046 return;
8458
8459
2/2
✓ Branch 0 taken 47 times.
✓ Branch 1 taken 14376393 times.
14376440 if(sfx_voice[index]!=-1)
8460 {
8461 47 deallocate_voice(sfx_voice[index]);
8462 47 sfx_voice[index]=-1;
8463 47 }
8464 14623486 }
8465
8466 // Stops SFX played by Hero's item of the given family
8467 163487 void stop_item_sfx(int32_t family)
8468 {
8469 163487 int32_t id=current_item_id(family);
8470
8471
2/2
✓ Branch 0 taken 162385 times.
✓ Branch 1 taken 1102 times.
163487 if(id<0)
8472 162385 return;
8473
8474 1102 stop_sfx(itemsbuf[id].usesound);
8475 163487 }
8476
8477 9349 void kill_sfx()
8478 {
8479
2/2
✓ Branch 0 taken 2393344 times.
✓ Branch 1 taken 9349 times.
2402693 for(int32_t i=0; i<WAV_COUNT; i++)
8480
2/2
✓ Branch 0 taken 2393286 times.
✓ Branch 1 taken 58 times.
2393402 if(sfx_voice[i]!=-1)
8481 {
8482 58 deallocate_voice(sfx_voice[i]);
8483 58 sfx_voice[i]=-1;
8484 58 }
8485 9349 }
8486
8487 // TODO: when far out of bounds, sounds should dampen. currently we only pan.
8488 1182150 int32_t pan(int32_t x)
8489 {
8490
1/5
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 1182150 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1182150 switch(pan_style)
8491 {
8492 // MONO
8493 case 0:
8494 return 128;
8495
8496 // 1/2
8497 case 1:
8498 1182150 x -= viewport.x;
8499 1182150 return vbound((x>>1)+68,0,255);
8500
8501 // 3/4
8502 case 2:
8503 x -= viewport.x;
8504 return vbound(((x*3)>>2)+36,0,255);
8505
8506 // FULL
8507 case 3:
8508 default:
8509 x -= viewport.x;
8510 return vbound(x,0,255);
8511 }
8512 1182150 }
8513
8514 50419317 bool joybtn(int32_t b)
8515 {
8516
1/2
✓ Branch 0 taken 50419317 times.
✗ Branch 1 not taken.
50419317 if(b == 0)
8517 return false;
8518
1/2
✓ Branch 0 taken 50419317 times.
✗ Branch 1 not taken.
50419317 if (b-1 >= joy[joystick_index].num_buttons)
8519 50419317 return false;
8520
8521 return joy[joystick_index].button[b-1].b !=0;
8522 50419317 }
8523
8524 bool joystick(int32_t s)
8525 {
8526 if(s < 0)
8527 return false;
8528 if (s >= joy[joystick_index].num_sticks)
8529 return false;
8530
8531 for (int i = 0; i < joy[joystick_index].stick[s].num_axis; i++)
8532 {
8533 if (joy[joystick_index].stick[s].axis[i].d1 || joy[joystick_index].stick[s].axis[i].d2)
8534 return true;
8535 }
8536 return false;
8537 }
8538
8539 const char* joybtn_name(int32_t b)
8540 {
8541 if (b <= 0 || b > joy[joystick_index].num_buttons)
8542 return "";
8543
8544 return joy[joystick_index].button[b-1].name;
8545 }
8546
8547 const char* joystick_name(int32_t s)
8548 {
8549 if (s < 0 || s >= joy[joystick_index].num_sticks)
8550 return "";
8551
8552 return joy[joystick_index].stick[s].name;
8553 }
8554
8555 int32_t button_pressed()
8556 {
8557 if (joystick_index >= MAX_JOYSTICKS)
8558 return 0;
8559
8560 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8561 {
8562 if(joybtn(i))
8563 return i;
8564 }
8565
8566 return 0;
8567 }
8568
8569 int32_t next_press_key();
8570
8571 int32_t next_joy_input(bool buttons)
8572 {
8573 clear_keybuf();
8574
8575 //first, we need to wait until they're pressing no buttons
8576 for(;;)
8577 {
8578 if(keypressed())
8579 {
8580 switch(readkey()>>8)
8581 {
8582 case KEY_ESC:
8583 return -1;
8584
8585 case KEY_SPACE:
8586 return 0;
8587 }
8588 }
8589
8590 poll_joystick();
8591 bool done = true;
8592
8593 if (buttons)
8594 {
8595 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8596 {
8597 if(joybtn(i)) done = false;
8598 }
8599 }
8600 else
8601 {
8602 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
8603 {
8604 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
8605 return -2;
8606 }
8607 for(int32_t i=0; i<joy[joystick_index].num_sticks; i++)
8608 {
8609 if(joystick(i)) done = false;
8610 }
8611 }
8612
8613 if(done) break;
8614 rest(1);
8615 }
8616
8617 //now, we need to wait for them to press any button
8618 for(;;)
8619 {
8620 if(keypressed())
8621 {
8622 switch(readkey()>>8)
8623 {
8624 case KEY_ESC:
8625 return -1;
8626
8627 case KEY_SPACE:
8628 return 0;
8629 }
8630 }
8631
8632 poll_joystick();
8633
8634 if (buttons)
8635 {
8636 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
8637 {
8638 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
8639 return -2;
8640 }
8641 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8642 {
8643 if(joybtn(i))
8644 return i;
8645 }
8646 }
8647 else
8648 {
8649 for(int32_t i=0; i<joy[joystick_index].num_sticks; i++)
8650 {
8651 if(joystick(i))
8652 return i;
8653 }
8654 }
8655 rest(1);
8656 }
8657 }
8658
8659 7887447 static bool rButton(bool &btn, bool &flag, bool rawbtn)
8660 {
8661
2/2
✓ Branch 0 taken 7859024 times.
✓ Branch 1 taken 28423 times.
7887447 bool ret = btn && !flag;
8662 7887447 flag = rawbtn;
8663
8664 7887447 return ret;
8665 }
8666 376997868 static bool rButton(bool &btn, bool &flag)
8667 {
8668
2/2
✓ Branch 0 taken 363077814 times.
✓ Branch 1 taken 13920054 times.
376997868 bool ret = btn && !flag;
8669 376997868 flag = btn;
8670
8671 376997868 return ret;
8672 }
8673 4643423 static bool rButtonPeek(bool btn, bool flag)
8674 {
8675
2/2
✓ Branch 0 taken 4296162 times.
✓ Branch 1 taken 347261 times.
4643423 if(!btn)
8676 {
8677 4296162 return false;
8678 }
8679
2/2
✓ Branch 0 taken 33613 times.
✓ Branch 1 taken 313648 times.
347261 else if(!flag)
8680 {
8681 33613 return true;
8682 }
8683
8684 313648 return false;
8685 4643423 }
8686
8687 // Updated only by keyboard/gamepad.
8688 // If in replay mode, this is set directly by the replay system.
8689 // This should never be read from directly - use control_state instead.
8690 bool raw_control_state[ZC_CONTROL_STATES];
8691
8692 // Every call to load_control_state (pretty much every frame) resets this to be equal to raw_control_state.
8693 // This state can drift from raw_control_state if button states are "eaten" or overriden by a script. But that only
8694 // lasts until the next call to load_control_state.
8695 bool control_state[ZC_CONTROL_STATES];
8696 bool disable_control[ZC_CONTROL_STATES];
8697 bool drunk_toggle_state[11];
8698 bool disabledKeys[127];
8699 bool KeyInput[127];
8700 bool KeyPress[127];
8701
8702 bool key_current_frame[127];
8703 bool key_previous_frame[127];
8704
8705 static bool key_system[127];
8706 static bool key_system_previous[127];
8707 static bool key_system_press[127];
8708
8709 bool button_press[ZC_CONTROL_STATES];
8710 bool button_hold[ZC_CONTROL_STATES];
8711
8712 #define STICK_1_X joy[joystick_index].stick[js_stick_1_x_stick].axis[js_stick_1_x_axis]
8713 #define STICK_1_Y joy[joystick_index].stick[js_stick_1_y_stick].axis[js_stick_1_y_axis]
8714 #define STICK_2_X joy[joystick_index].stick[js_stick_2_x_stick].axis[js_stick_2_x_axis]
8715 #define STICK_2_Y joy[joystick_index].stick[js_stick_2_y_stick].axis[js_stick_2_y_axis]
8716 #define STICK_PRECISION 56 //define your own sensitivity
8717
8718 15669428 void load_control_state()
8719 {
8720 15669428 load_control_called_this_frame = true;
8721
8722
2/2
✓ Branch 0 taken 12466366 times.
✓ Branch 1 taken 3203062 times.
15669428 if (replay_version_check(8, 11))
8723 {
8724
2/2
✓ Branch 0 taken 57655116 times.
✓ Branch 1 taken 3203062 times.
60858178 for (int i = 0; i < ZC_CONTROL_STATES; i++)
8725 57655116 down_control_states[i] = raw_control_state[i];
8726 3203062 }
8727
8728
2/2
✓ Branch 0 taken 15669407 times.
✓ Branch 1 taken 21 times.
15669428 if (!replay_is_replaying())
8729 {
8730
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[0]=zc_getrawkey(DUkey, true)||(analog_movement ? STICK_1_Y.d1 || STICK_1_Y.pos - js_stick_1_y_offset < -STICK_PRECISION : joybtn(DUbtn));
8731
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[1]=zc_getrawkey(DDkey, true)||(analog_movement ? STICK_1_Y.d2 || STICK_1_Y.pos - js_stick_1_y_offset > STICK_PRECISION : joybtn(DDbtn));
8732
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[2]=zc_getrawkey(DLkey, true)||(analog_movement ? STICK_1_X.d1 || STICK_1_X.pos - js_stick_1_x_offset < -STICK_PRECISION : joybtn(DLbtn));
8733
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[3]=zc_getrawkey(DRkey, true)||(analog_movement ? STICK_1_X.d2 || STICK_1_X.pos - js_stick_1_x_offset > STICK_PRECISION : joybtn(DRbtn));
8734
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[4]=zc_getrawkey(Akey, true)||joybtn(Abtn);
8735
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[5]=zc_getrawkey(Bkey, true)||joybtn(Bbtn);
8736
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[6]=zc_getrawkey(Skey, true)||joybtn(Sbtn);
8737
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[7]=zc_getrawkey(Lkey, true)||joybtn(Lbtn);
8738
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[8]=zc_getrawkey(Rkey, true)||joybtn(Rbtn);
8739
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[9]=zc_getrawkey(Pkey, true)||joybtn(Pbtn);
8740
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[10]=zc_getrawkey(Exkey1, true)||joybtn(Exbtn1);
8741
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[11]=zc_getrawkey(Exkey2, true)||joybtn(Exbtn2);
8742
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[12]=zc_getrawkey(Exkey3, true)||joybtn(Exbtn3);
8743
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[13]=zc_getrawkey(Exkey4, true)||joybtn(Exbtn4);
8744
8745
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 if(num_joysticks != 0)
8746 {
8747 raw_control_state[14] = STICK_2_Y.pos - js_stick_2_y_offset < -STICK_PRECISION;
8748 raw_control_state[15] = STICK_2_Y.pos - js_stick_2_y_offset > STICK_PRECISION;
8749 raw_control_state[16] = STICK_2_X.pos - js_stick_2_x_offset < -STICK_PRECISION;
8750 raw_control_state[17] = STICK_2_X.pos - js_stick_2_x_offset > STICK_PRECISION;
8751 }
8752 else
8753 {
8754 21 raw_control_state[14] = false;
8755 21 raw_control_state[15] = false;
8756 21 raw_control_state[16] = false;
8757 21 raw_control_state[17] = false;
8758 }
8759 21 }
8760
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 15669423 times.
15669428 if (replay_is_active())
8761 {
8762
2/2
✓ Branch 0 taken 1211700 times.
✓ Branch 1 taken 14457723 times.
15669423 if (replay_get_version() < 3)
8763 1211700 replay_poll();
8764
4/4
✓ Branch 0 taken 14457702 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 12696327 times.
✓ Branch 3 taken 1761375 times.
14457723 else if (replay_is_replaying() && replay_get_version() < 6)
8765 1761375 replay_peek_input();
8766
4/4
✓ Branch 0 taken 12696327 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 9493265 times.
✓ Branch 3 taken 3203062 times.
12696348 else if (replay_is_replaying() && replay_version_check(8, 11))
8767 3203062 replay_peek_input();
8768
2/2
✓ Branch 0 taken 14329481 times.
✓ Branch 1 taken 1339942 times.
15669423 if (replay_get_version() == 8)
8769 1339942 update_keys();
8770 15669423 }
8771
8772 // Some test replay files were made before a serious input bug was fixed, so instead
8773 // of re-doing them or tossing them out, just check for that zplay version.
8774
3/4
✓ Branch 0 taken 15669418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 121900 times.
✓ Branch 3 taken 15547518 times.
15669428 bool botched_input = replay_is_active() && replay_get_version() != 1 && replay_get_version() < 8;
8775
2/2
✓ Branch 0 taken 282049524 times.
✓ Branch 1 taken 15669418 times.
297718942 for (int i = 0; i < ZC_CONTROL_STATES; i++)
8776 {
8777 282049524 control_state[i] = raw_control_state[i];
8778
4/4
✓ Branch 0 taken 53024022 times.
✓ Branch 1 taken 229025502 times.
✓ Branch 2 taken 2611994 times.
✓ Branch 3 taken 50412028 times.
282049524 if (botched_input && !control_state[i])
8779 50412028 down_control_states[i] = false;
8780 282049524 }
8781 15669418 bool did_bad_cutscene_btn = false;
8782
2/2
✓ Branch 0 taken 15669418 times.
✓ Branch 1 taken 282049524 times.
297718942 for(int q = 0; q < 18; ++q)
8783
4/4
✓ Branch 0 taken 13344598 times.
✓ Branch 1 taken 268704926 times.
✓ Branch 2 taken 13343015 times.
✓ Branch 3 taken 1583 times.
282051107 if(control_state[q] && !active_cutscene.can_button(q))
8784 {
8785 1583 control_state[q] = false;
8786 1583 did_bad_cutscene_btn = true;
8787 1583 }
8788
2/2
✓ Branch 0 taken 15668273 times.
✓ Branch 1 taken 1145 times.
15669418 if(did_bad_cutscene_btn)
8789 1145 active_cutscene.error();
8790
8791 15669418 button_press[0]=rButton(control_state[0],button_hold[0]);
8792 15669418 button_press[1]=rButton(control_state[1],button_hold[1]);
8793 15669418 button_press[2]=rButton(control_state[2],button_hold[2]);
8794 15669418 button_press[3]=rButton(control_state[3],button_hold[3]);
8795 15669418 button_press[4]=rButton(control_state[4],button_hold[4]);
8796 15669418 button_press[5]=rButton(control_state[5],button_hold[5]);
8797 15669418 button_press[6]=rButton(control_state[6],button_hold[6]);
8798 15669418 button_press[7]=rButton(control_state[7],button_hold[7]);
8799 15669418 button_press[8]=rButton(control_state[8],button_hold[8]);
8800 15669418 button_press[9]=rButton(control_state[9],button_hold[9]);
8801 15669418 button_press[10]=rButton(control_state[10],button_hold[10]);
8802 15669418 button_press[11]=rButton(control_state[11],button_hold[11]);
8803 15669418 button_press[12]=rButton(control_state[12],button_hold[12]);
8804 15669418 button_press[13]=rButton(control_state[13],button_hold[13]);
8805 15669418 button_press[14]=rButton(control_state[14],button_hold[14]);
8806 15669418 button_press[15]=rButton(control_state[15],button_hold[15]);
8807 15669418 button_press[16]=rButton(control_state[16],button_hold[16]);
8808 15669418 button_press[17]=rButton(control_state[17],button_hold[17]);
8809 15669418 }
8810
8811 // Returns true if any game key is pressed. This is needed because keypressed()
8812 // doesn't detect modifier keys and control_state[] can be modified by scripts.
8813 78803580 bool zc_key_pressed()
8814 //may also need to use zc_getrawkey
8815 {
8816
7/10
✓ Branch 0 taken 63645875 times.
✓ Branch 1 taken 15157705 times.
✓ Branch 2 taken 15157705 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15157705 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 12421076 times.
✓ Branch 7 taken 12421076 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4961239 times.
83764819 if((zc_getrawkey(DUkey, true)||(analog_movement ? STICK_1_Y.d1 || STICK_1_Y.pos - js_stick_1_y_offset< -STICK_PRECISION : joybtn(DUbtn))) ||
8817
4/6
✓ Branch 0 taken 12421076 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12421076 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9456835 times.
✓ Branch 5 taken 9456835 times.
12421076 (zc_getrawkey(DDkey, true)||(analog_movement ? STICK_1_Y.d2 || STICK_1_Y.pos - js_stick_1_y_offset > STICK_PRECISION : joybtn(DDbtn))) ||
8818
4/6
✓ Branch 0 taken 9456835 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9456835 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6257925 times.
✓ Branch 5 taken 6257925 times.
9456835 (zc_getrawkey(DLkey, true)||(analog_movement ? STICK_1_X.d1 || STICK_1_X.pos - js_stick_1_x_offset < -STICK_PRECISION : joybtn(DLbtn))) ||
8819
4/6
✓ Branch 0 taken 6257925 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6257925 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5370467 times.
✓ Branch 5 taken 5370467 times.
6257925 (zc_getrawkey(DRkey, true)||(analog_movement ? STICK_1_X.d2 || STICK_1_X.pos - js_stick_1_x_offset > STICK_PRECISION : joybtn(DRbtn))) ||
8820
1/2
✓ Branch 0 taken 5370467 times.
✗ Branch 1 not taken.
5370467 (zc_getrawkey(Akey, true)||joybtn(Abtn)) ||
8821
3/4
✓ Branch 0 taken 5183199 times.
✓ Branch 1 taken 187268 times.
✓ Branch 2 taken 5183199 times.
✗ Branch 3 not taken.
5370467 (zc_getrawkey(Bkey, true)||joybtn(Bbtn)) ||
8822
3/4
✓ Branch 0 taken 5036267 times.
✓ Branch 1 taken 146932 times.
✓ Branch 2 taken 5036267 times.
✗ Branch 3 not taken.
5183199 (zc_getrawkey(Skey, true)||joybtn(Sbtn)) ||
8823
3/4
✓ Branch 0 taken 5014055 times.
✓ Branch 1 taken 22212 times.
✓ Branch 2 taken 5014055 times.
✗ Branch 3 not taken.
5036267 (zc_getrawkey(Lkey, true)||joybtn(Lbtn)) ||
8824
3/4
✓ Branch 0 taken 4987686 times.
✓ Branch 1 taken 26369 times.
✓ Branch 2 taken 4987686 times.
✗ Branch 3 not taken.
5014055 (zc_getrawkey(Rkey, true)||joybtn(Rbtn)) ||
8825
3/4
✓ Branch 0 taken 4980401 times.
✓ Branch 1 taken 7285 times.
✓ Branch 2 taken 4980401 times.
✗ Branch 3 not taken.
4987686 (zc_getrawkey(Pkey, true)||joybtn(Pbtn)) ||
8826
3/4
✓ Branch 0 taken 4963162 times.
✓ Branch 1 taken 17239 times.
✓ Branch 2 taken 4963162 times.
✗ Branch 3 not taken.
4980401 (zc_getrawkey(Exkey1, true)||joybtn(Exbtn1)) ||
8827
3/4
✓ Branch 0 taken 4961333 times.
✓ Branch 1 taken 1829 times.
✓ Branch 2 taken 4961333 times.
✗ Branch 3 not taken.
4963162 (zc_getrawkey(Exkey2, true)||joybtn(Exbtn2)) ||
8828
3/4
✓ Branch 0 taken 4961298 times.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 4961298 times.
✗ Branch 3 not taken.
4961333 (zc_getrawkey(Exkey3, true)||joybtn(Exbtn3)) ||
8829
2/2
✓ Branch 0 taken 4961239 times.
✓ Branch 1 taken 59 times.
4961298 (zc_getrawkey(Exkey4, true)||joybtn(Exbtn4))) // Skipping joystick axes
8830 140854947 return true;
8831
8832 4961239 return false;
8833 18524436 }
8834
8835 298013475 bool getInput(int32_t btn, bool press, bool drunk, bool ignoreDisable, bool eatEntirely, bool peek)
8836 {
8837 298013475 bool ret = false, drunkstate = false, rawret = false;;
8838 298013475 bool* flag = &down_control_states[btn];
8839
2/7
✓ Branch 0 taken 279470131 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 18543344 times.
298013475 switch(btn)
8840 {
8841 case btnF12:
8842 ret = zc_getkey(KEY_F12, ignoreDisable);
8843 rawret = zc_getrawkey(KEY_F12, ignoreDisable);
8844 eatEntirely = false;
8845 break;
8846 case btnF11:
8847 ret = zc_getkey(KEY_F11, ignoreDisable);
8848 rawret = zc_getrawkey(KEY_F11, ignoreDisable);
8849 eatEntirely = false;
8850 break;
8851 case btnF5:
8852 ret = zc_getkey(KEY_F5, ignoreDisable);
8853 rawret = zc_getrawkey(KEY_F5, ignoreDisable);
8854 eatEntirely = false;
8855 break;
8856 case btnQ:
8857 ret = zc_getkey(KEY_Q, ignoreDisable);
8858 rawret = zc_getrawkey(KEY_Q, ignoreDisable);
8859 eatEntirely = false;
8860 break;
8861 case btnI:
8862 ret = zc_getkey(KEY_I, ignoreDisable);
8863 rawret = zc_getrawkey(KEY_I, ignoreDisable);
8864 eatEntirely = false;
8865 break;
8866 case btnM:
8867
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18543344 times.
18543344 if(FFCore.kb_typing_mode) return false;
8868 18543344 rawret = ret = zc_getrawkey(KEY_ESC, ignoreDisable);
8869 18543344 eatEntirely = false;
8870 18543344 break;
8871 default: //control_state[] index
8872
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 279470131 times.
279470131 if(FFCore.kb_typing_mode) return false;
8873
6/6
✓ Branch 0 taken 278090464 times.
✓ Branch 1 taken 1379667 times.
✓ Branch 2 taken 18131668 times.
✓ Branch 3 taken 259958796 times.
✓ Branch 4 taken 18128695 times.
✓ Branch 5 taken 2973 times.
279470131 if(!ignoreDisable && get_qr(qr_FIXDRUNKINPUTS) && disable_control[btn]) drunk = false;
8874
2/2
✓ Branch 0 taken 15934827 times.
✓ Branch 1 taken 263532331 times.
279467158 else if(btn<11) drunkstate = drunk_toggle_state[btn];
8875
4/4
✓ Branch 0 taken 248289128 times.
✓ Branch 1 taken 31181003 times.
✓ Branch 2 taken 7136 times.
✓ Branch 3 taken 31173867 times.
310651134 ret = control_state[btn] && (ignoreDisable || !disable_control[btn]);
8876 279470131 rawret = raw_control_state[btn];
8877 279470131 }
8878
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 298013475 times.
298013475 assert(flag);
8879
2/2
✓ Branch 0 taken 190534261 times.
✓ Branch 1 taken 107479214 times.
298013475 if(press)
8880 {
8881
2/2
✓ Branch 0 taken 4643423 times.
✓ Branch 1 taken 102835791 times.
107479214 if(peek)
8882 4643423 ret = rButtonPeek(ret, *flag);
8883
2/2
✓ Branch 0 taken 94948344 times.
✓ Branch 1 taken 7887447 times.
102835791 else if(get_qr(qr_BROKEN_INPUT_DOWN_STATE)) ret = rButton(ret, *flag);
8884 7887447 else ret = rButton(ret, *flag, rawret);
8885 107479214 }
8886
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 298013475 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
298013475 if(eatEntirely && ret) control_state[btn] = false;
8887
4/4
✓ Branch 0 taken 222509954 times.
✓ Branch 1 taken 75503521 times.
✓ Branch 2 taken 222509873 times.
✓ Branch 3 taken 81 times.
298013475 if(drunk && drunkstate) ret = !ret;
8888 298013475 return ret;
8889 298013475 }
8890
8891 15045996 byte getIntBtnInput(byte intbtn, bool press, bool drunk, bool ignoreDisable, bool eatEntirely, bool peek)
8892 {
8893 15045996 byte ret = 0;
8894
2/2
✓ Branch 0 taken 10624705 times.
✓ Branch 1 taken 4421291 times.
15045996 if(intbtn & INT_BTN_A) ret |= getInput(btnA, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_A : 0;
8895
2/2
✓ Branch 0 taken 14837030 times.
✓ Branch 1 taken 208966 times.
15045996 if(intbtn & INT_BTN_B) ret |= getInput(btnB, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_B : 0;
8896
2/2
✓ Branch 0 taken 14838348 times.
✓ Branch 1 taken 207648 times.
15045996 if(intbtn & INT_BTN_L) ret |= getInput(btnL, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_L : 0;
8897
2/2
✓ Branch 0 taken 14838348 times.
✓ Branch 1 taken 207648 times.
15045996 if(intbtn & INT_BTN_R) ret |= getInput(btnR, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_R : 0;
8898
2/2
✓ Branch 0 taken 14838348 times.
✓ Branch 1 taken 207648 times.
15045996 if(intbtn & INT_BTN_EX1) ret |= getInput(btnEx1, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX1 : 0;
8899
2/2
✓ Branch 0 taken 14838348 times.
✓ Branch 1 taken 207648 times.
15045996 if(intbtn & INT_BTN_EX2) ret |= getInput(btnEx2, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX2 : 0;
8900
2/2
✓ Branch 0 taken 14838348 times.
✓ Branch 1 taken 207648 times.
15045996 if(intbtn & INT_BTN_EX3) ret |= getInput(btnEx3, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX3 : 0;
8901
2/2
✓ Branch 0 taken 14838233 times.
✓ Branch 1 taken 207763 times.
15045996 if(intbtn & INT_BTN_EX4) ret |= getInput(btnEx4, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX4 : 0;
8902 15045996 return ret; //No early return, to make sure all button presses are eaten that should be! -Em
8903 }
8904
8905 7641 byte checkIntBtnVal(byte intbtn, byte vals)
8906 {
8907 7641 return intbtn&vals;
8908 }
8909
8910 3769225 bool Up()
8911 {
8912 3769225 return getInput(btnUp);
8913 }
8914 741510 bool Down()
8915 {
8916 741510 return getInput(btnDown);
8917 }
8918 1011055 bool Left()
8919 {
8920 1011055 return getInput(btnLeft);
8921 }
8922 1079337 bool Right()
8923 {
8924 1079337 return getInput(btnRight);
8925 }
8926 530491 bool cAbtn()
8927 {
8928 530491 return getInput(btnA);
8929 }
8930 3306738 bool cBbtn()
8931 {
8932 3306738 return getInput(btnB);
8933 }
8934 bool cSbtn()
8935 {
8936 return getInput(btnS);
8937 }
8938 208608 bool cLbtn()
8939 {
8940 208608 return getInput(btnL);
8941 }
8942 208608 bool cRbtn()
8943 {
8944 208608 return getInput(btnR);
8945 }
8946 bool cPbtn()
8947 {
8948 return getInput(btnP);
8949 }
8950 bool cEx1btn()
8951 {
8952 return getInput(btnEx1);
8953 }
8954 bool cEx2btn()
8955 {
8956 return getInput(btnEx2);
8957 }
8958 bool cEx3btn()
8959 {
8960 return getInput(btnEx3);
8961 }
8962 bool cEx4btn()
8963 {
8964 return getInput(btnEx4);
8965 }
8966 bool AxisUp()
8967 {
8968 return getInput(btnAxisUp);
8969 }
8970 bool AxisDown()
8971 {
8972 return getInput(btnAxisDown);
8973 }
8974 bool AxisLeft()
8975 {
8976 return getInput(btnAxisLeft);
8977 }
8978 bool AxisRight()
8979 {
8980 return getInput(btnAxisRight);
8981 }
8982
8983 bool cMbtn()
8984 {
8985 return getInput(btnM);
8986 }
8987 bool cF12()
8988 {
8989 return getInput(btnF12);
8990 }
8991 bool cF11()
8992 {
8993 return getInput(btnF11);
8994 }
8995 bool cF5()
8996 {
8997 return getInput(btnF5);
8998 }
8999 bool cQ()
9000 {
9001 return getInput(btnQ);
9002 }
9003 bool cI()
9004 {
9005 return getInput(btnI);
9006 }
9007
9008 211312 bool rUp()
9009 {
9010 211312 return getInput(btnUp, true);
9011 }
9012 211099 bool rDown()
9013 {
9014 211099 return getInput(btnDown, true);
9015 }
9016 210903 bool rLeft()
9017 {
9018 210903 return getInput(btnLeft, true);
9019 }
9020 210163 bool rRight()
9021 {
9022 210163 return getInput(btnRight, true);
9023 }
9024 7058 bool rAbtn()
9025 {
9026 7058 return getInput(btnA, true);
9027 }
9028 2410 bool rBbtn()
9029 {
9030 2410 return getInput(btnB, true);
9031 }
9032 14522636 bool rSbtn()
9033 {
9034 14522636 return getInput(btnS, true);
9035 }
9036 18524436 bool rMbtn()
9037 {
9038 18524436 return getInput(btnM, true);
9039 }
9040 186046 bool rLbtn()
9041 {
9042 186046 return getInput(btnL, true);
9043 }
9044 186041 bool rRbtn()
9045 {
9046 186041 return getInput(btnR, true);
9047 }
9048 14522515 bool rPbtn()
9049 {
9050 14522515 return getInput(btnP, true);
9051 }
9052 bool rEx1btn()
9053 {
9054 return getInput(btnEx1, true);
9055 }
9056 bool rEx2btn()
9057 {
9058 return getInput(btnEx2, true);
9059 }
9060 196692 bool rEx3btn()
9061 {
9062 196692 return getInput(btnEx3, true);
9063 }
9064 196692 bool rEx4btn()
9065 {
9066 196692 return getInput(btnEx4, true);
9067 }
9068 bool rAxisUp()
9069 {
9070 return getInput(btnAxisUp, true);
9071 }
9072 bool rAxisDown()
9073 {
9074 return getInput(btnAxisDown, true);
9075 }
9076 bool rAxisLeft()
9077 {
9078 return getInput(btnAxisLeft, true);
9079 }
9080 bool rAxisRight()
9081 {
9082 return getInput(btnAxisRight, true);
9083 }
9084
9085 bool rF11()
9086 {
9087 return getInput(btnF11, true);
9088 }
9089 bool rQ()
9090 {
9091 return getInput(btnQ, true);
9092 }
9093 bool rI()
9094 {
9095 return getInput(btnI, true);
9096 }
9097
9098 37014896 bool DrunkUp()
9099 {
9100 37014896 return getInput(btnUp, false, true);
9101 }
9102 33784579 bool DrunkDown()
9103 {
9104 33784579 return getInput(btnDown, false, true);
9105 }
9106 19759675 bool DrunkLeft()
9107 {
9108 19759675 return getInput(btnLeft, false, true);
9109 }
9110 16791546 bool DrunkRight()
9111 {
9112 16791546 return getInput(btnRight, false, true);
9113 }
9114 15933991 bool DrunkcAbtn()
9115 {
9116 15933991 return getInput(btnA, false, true);
9117 }
9118 15366659 bool DrunkcBbtn()
9119 {
9120 15366659 return getInput(btnB, false, true);
9121 }
9122 14313714 bool DrunkcEx1btn()
9123 {
9124 14313714 return getInput(btnEx1, false, true);
9125 }
9126 14312346 bool DrunkcEx2btn()
9127 {
9128 14312346 return getInput(btnEx2, false, true);
9129 }
9130 bool DrunkcSbtn()
9131 {
9132 return getInput(btnS, false, true);
9133 }
9134 bool DrunkcMbtn()
9135 {
9136 return getInput(btnM, false, true);
9137 }
9138 bool DrunkcLbtn()
9139 {
9140 return getInput(btnL, false, true);
9141 }
9142 bool DrunkcRbtn()
9143 {
9144 return getInput(btnR, false, true);
9145 }
9146 bool DrunkcPbtn()
9147 {
9148 return getInput(btnP, false, true);
9149 }
9150
9151 bool DrunkrUp()
9152 {
9153 return getInput(btnUp, true, true);
9154 }
9155 bool DrunkrDown()
9156 {
9157 return getInput(btnDown, true, true);
9158 }
9159 bool DrunkrLeft()
9160 {
9161 return getInput(btnLeft, true, true);
9162 }
9163 bool DrunkrRight()
9164 {
9165 return getInput(btnRight, true, true);
9166 }
9167 11971385 bool DrunkrAbtn()
9168 {
9169 11971385 return getInput(btnA, true, true);
9170 }
9171 12000048 bool DrunkrBbtn()
9172 {
9173 12000048 return getInput(btnB, true, true);
9174 }
9175 549513 bool DrunkrEx1btn()
9176 {
9177 549513 return getInput(btnEx1, true, true);
9178 }
9179 549314 bool DrunkrEx2btn()
9180 {
9181 549314 return getInput(btnEx2, true, true);
9182 }
9183 bool DrunkrEx3btn()
9184 {
9185 return getInput(btnEx3, true, true);
9186 }
9187 bool DrunkrEx4btn()
9188 {
9189 return getInput(btnEx4, true, true);
9190 }
9191 bool DrunkrSbtn()
9192 {
9193 return getInput(btnS, true, true);
9194 }
9195 bool DrunkrMbtn()
9196 {
9197 return getInput(btnM, true, true);
9198 }
9199 12975715 bool DrunkrLbtn()
9200 {
9201 12975715 return getInput(btnL, true, true);
9202 }
9203 12970401 bool DrunkrRbtn()
9204 {
9205 12970401 return getInput(btnR, true, true);
9206 }
9207 bool DrunkrPbtn()
9208 {
9209 return getInput(btnP, true, true);
9210 }
9211
9212 18908 void eat_buttons()
9213 {
9214 18908 getInput(btnA, true, false, true);
9215 18908 getInput(btnB, true, false, true);
9216 18908 getInput(btnS, true, false, true);
9217 18908 getInput(btnM, true, false, true);
9218 18908 getInput(btnL, true, false, true);
9219 18908 getInput(btnR, true, false, true);
9220 18908 getInput(btnP, true, false, true);
9221 18908 getInput(btnEx1, true, false, true);
9222 18908 getInput(btnEx2, true, false, true);
9223 18908 getInput(btnEx3, true, false, true);
9224 18908 getInput(btnEx4, true, false, true);
9225 18908 }
9226
9227 // Is true for the _first frame_ of a key press.
9228 // But! it is possible that a script manually sets the value of KeyPress,
9229 // in which case it will be restored to the "true" value based on `key_current_frame`
9230 // and `key_previous_frame` on the next frame.
9231 46 bool zc_readkey(int32_t k, bool ignoreDisable)
9232 {
9233
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if(ignoreDisable) return KeyPress[k];
9234
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 switch(k)
9235 {
9236 case KEY_F7:
9237 case KEY_F8:
9238 case KEY_F9:
9239 return KeyPress[k];
9240
9241 default:
9242
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 return KeyPress[k] && !disabledKeys[k];
9243 }
9244 46 }
9245
9246 // Is true for _every frame_ a key is held down.
9247 // But! it is possible that a script manually sets the value of KeyInput,
9248 // in which case it will be restored to the "true" value based on `key_current_frame`
9249 // on the next frame.
9250 bool zc_getkey(int32_t k, bool ignoreDisable)
9251 {
9252 if(ignoreDisable) return KeyInput[k];
9253 switch(k)
9254 {
9255 case KEY_F7:
9256 case KEY_F8:
9257 case KEY_F9:
9258 return KeyInput[k];
9259
9260 default:
9261 return KeyInput[k] && !disabledKeys[k];
9262 }
9263 }
9264
9265 // Reads (and then clears) the current frame key state directly.
9266 // Scripts can also modify `key_current_frame`.
9267 900 bool zc_readrawkey(int32_t k, bool ignoreDisable)
9268 {
9269
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 898 times.
900 if(zc_getrawkey(k, ignoreDisable))
9270 {
9271 2 _key[k]=key[k]=key_current_frame[k]=0;
9272 2 return true;
9273 }
9274 898 _key[k]=key[k]=key_current_frame[k]=0;
9275 898 return false;
9276 900 }
9277
9278 // Reads the current frame key state directly.
9279 // Scripts can also modify `key_current_frame`.
9280 125820383 bool zc_getrawkey(int32_t k, bool ignoreDisable)
9281 {
9282
2/2
✓ Branch 0 taken 107295855 times.
✓ Branch 1 taken 18524528 times.
125820383 if(ignoreDisable) return key_current_frame[k];
9283
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18524528 times.
18524528 switch(k)
9284 {
9285 case KEY_F7:
9286 case KEY_F8:
9287 case KEY_F9:
9288 return key_current_frame[k];
9289
9290 default:
9291
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18524528 times.
18524528 return key_current_frame[k] && !disabledKeys[k];
9292 }
9293 125820383 }
9294
9295 // Only used for a handful of keys, like tilde and Function keys.
9296 // This state is never read within the game.
9297 // It exists so that all keyboard input still functions during replay,
9298 // without inadvertently doing things like toggling throttling if the player
9299 // presses ~
9300 bool zc_get_system_key(int32_t k)
9301 {
9302 return key_system[k];
9303 }
9304
9305 // True for the _first_ frame of a key press.
9306 166719924 bool zc_read_system_key(int32_t k)
9307 {
9308 166719924 return key_system_press[k];
9309 }
9310
9311 2352603372 bool is_system_key(int32_t k)
9312 {
9313
2/2
✓ Branch 0 taken 2185883448 times.
✓ Branch 1 taken 166719924 times.
2352603372 switch (k)
9314 {
9315 case KEY_BACKQUOTE:
9316 case KEY_CLOSEBRACE:
9317 case KEY_END:
9318 case KEY_HOME:
9319 case KEY_OPENBRACE:
9320 case KEY_PGDN:
9321 case KEY_PGUP:
9322 case KEY_TAB:
9323 case KEY_TILDE:
9324 166719924 return true;
9325 }
9326 2185883448 return is_Fkey(k);
9327 2352603372 }
9328
9329 18524436 void update_system_keys()
9330 {
9331
2/2
✓ Branch 0 taken 2352603372 times.
✓ Branch 1 taken 18524436 times.
2371127808 for (int32_t q = 0; q < 127; ++q)
9332 {
9333
2/2
✓ Branch 0 taken 389013156 times.
✓ Branch 1 taken 1963590216 times.
2352603372 if (!is_system_key(q))
9334 1963590216 continue;
9335
9336 389013156 key_system[q] = key[q];
9337
1/2
✓ Branch 0 taken 389013156 times.
✗ Branch 1 not taken.
389013156 key_system_press[q] = key_system[q] && !key_system_previous[q];
9338 389013156 key_system_previous[q] = key_system[q];
9339 389013156 }
9340 18524436 }
9341
9342 19864378 void update_keys()
9343 {
9344
2/2
✓ Branch 0 taken 2522776006 times.
✓ Branch 1 taken 19864378 times.
2542640384 for (int32_t q = 0; q < 127; ++q)
9345 {
9346 // When replaying, replay.cpp takes care of updating `key_current_frame`.
9347
2/2
✓ Branch 0 taken 2522763306 times.
✓ Branch 1 taken 12700 times.
2522776006 if (!replay_is_replaying())
9348 12700 key_current_frame[q] = key[q];
9349
9350
2/2
✓ Branch 0 taken 2503387033 times.
✓ Branch 1 taken 19388973 times.
2522776006 KeyPress[q] = key_current_frame[q] && !key_previous_frame[q];
9351 2522776006 KeyInput[q] = key_current_frame[q];
9352 2522776006 key_previous_frame[q] = key_current_frame[q];
9353 2522776006 }
9354 19864378 }
9355
9356